January 07, 2012

TextField integer/Number validator in java swing

Example show how to create a text field in java swing that accepts only numbers
initializing variable

private JFormattedTextField expAmount_txt = null;
adding to container

private JFormattedTextField getExpAmount_txt() {
if (expAmount_txt == null) {
Format general = NumberFormat.getInstance();
expAmount_txt = new JFormattedTextField(general);
expAmount_txt.setBounds(new Rectangle(120, 40, 120, 20));
return expAmount_txt;

Thanking you..........

Facebook comments