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
panel.add(getExpAmount_txt(),null);
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));
expAmount_txt.setHorizontalAlignment(JFormattedTextField.RIGHT);
}
return expAmount_txt;
}
retrieving value
Double.parseDouble(expAmount_txt.getValue().toString());
Similar posts
Thanking you..........
No comments:
Post a Comment
Your feedback may help others !!!