Expert:valarmathi
Hi,
This is my code. How can i set the jtextfield validation in numeric value only. Please change the code.If i insert otherthan number it displays error message.
package com.zsl.ibm.mqtool;
import java.awt.Color; import java.awt.Font;
import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.UIManager;
class OSInformation extends JPanel { /** * */ private static final long serialVersionUID = 752052456706205768L;
public OSInformation() {
JLabel osname, osversion, osarchitecture, javapathname, javalibrarypath, javatemppath,ostitlelabel;
JTextField osnametext, ostextversion, ostextarch, javatextpath, javatextlibrary, javatemptextpath; // Fetch icon Icon icon = new ImageIcon("e:\\logo.gif"); // Create a label with text and an icon; the icon appears to the left of the text JLabel label = new JLabel("Text Label", icon, JLabel.CENTER); // Create a label with only an icon label = new JLabel(icon);
// Add an icon to an existing label label.setIcon(icon); add(label); label.setBounds(0, 0, 150,80);
ostitlelabel =new JLabel("Current Working OS"); ostitlelabel.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 16)); //ostitlelabel.setForeground(Color.MAGENTA); ostitlelabel.setForeground(Color.decode("#660033")); osname = new JLabel("OS Name"); osnametext = new JTextField(33); osnametext.setEditable(false); String osName = System.getProperty("os.name"); osnametext.setToolTipText("Current Working OS Name"); osnametext.setText(osName); osname.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
osversion = new JLabel("OS Version"); ostextversion = new JTextField(33); ostextversion.setEditable(false); String osVersion = System.getProperty("os.version"); ostextversion.setText(osVersion); ostextversion.setToolTipText("Current Working OS Version"); osversion.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
osarchitecture = new JLabel("OS Architecture"); ostextarch = new JTextField(33); ostextarch.setEditable(false); String osType = System.getProperty("os.arch"); ostextarch.setText(osType); ostextarch.setToolTipText("Current Working architecture"); osarchitecture.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
javapathname = new JLabel("Java Path"); javatextpath = new JTextField(33); javatextpath.setToolTipText("Java Installation Path"); javatextpath.setEditable(false); String jPathName = System.getProperty("java.home"); javatextpath.setText(jPathName); javapathname.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
javalibrarypath = new JLabel("Java Library Path"); javatextlibrary = new JTextField(33); javatextlibrary.setEditable(false); String jlibraryPath = System.getProperty("java.library.path"); javatextlibrary.setText(jlibraryPath); javatextlibrary.setToolTipText("Java Library Path"); javalibrarypath.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
javatemppath = new JLabel("Java Temp Directory"); javatemptextpath = new JTextField(33); javatemptextpath.setEditable(false); String jTempPath = System.getProperty("java.io.tmpdir"); javatemptextpath.setText(jTempPath); javatemptextpath.setToolTipText("Java Temprary Directory Path"); javatemppath.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 12));
setLayout(null);
add(ostitlelabel); ostitlelabel.setBounds(190, 40, 170, 20); add(osname); add(osnametext); osname.setBounds(110, 100, 160, 14); osnametext.setBounds(290, 100, 180, 20);
add(osversion); add(ostextversion); osversion.setBounds(110, 140, 160, 14); ostextversion.setBounds(290, 140, 180, 20);
add(osarchitecture); add(ostextarch); osarchitecture.setBounds(110, 180, 180, 14); ostextarch.setBounds(290, 180, 180, 20);
add(javapathname); add(javatextpath); javapathname.setBounds(110, 220, 160, 14); javatextpath.setBounds(290, 220, 180, 20);
add(javalibrarypath); add(javatextlibrary); javalibrarypath.setBounds(110, 260, 160, 14); javatextlibrary.setBounds(290, 260, 180, 20);
add(javatemppath); add(javatemptextpath); javatemppath.setBounds(110, 300, 160, 14); javatemptextpath.setBounds(290, 300, 180, 20);
setBackground(Color.decode("#99CC99"));
} }
This is very urgent.
Thanks, Valarmathi |