Reputation:
How can I add just numbers betwwen 0 and 255 in a FormattedTextField in Java?
I tried this way :
private JFormattedTextField text4;
//...
text4= new JFormattedTextField(paymentFormat);
text4.getValue();
text4.setColumns(3);
try {
MaskFormatter mask = new MaskFormatter("###");
mask.install(text4);
} catch (ParseException ex) {
System.out.print("Valoarea nu e corecta");
}
and it doesn`t work...
Upvotes: 0
Views: 249
Reputation: 109813
there are two ways
use JSpinner instead of JFormattedTextField
, to set proper range in SpinnerNumberModel
add DocumentFilter to JFormattedTextField, and determine if Integer, Double value is less than 0 and more than 255
add DocumentListener to display overloading for JFormattedTextField
Upvotes: 1