如何在 Java 的 JFormattedTextField 中仅添加 0 到 255 之间的数字?
我尝试了这种方式:
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");
}
它不起作用...
最佳答案
有两种方法
使用JSpinner而不是
JFormattedTextField
,设置 proper range in SpinnerNumberModel添加DocumentFilter to JFormattedTextField ,判断Integer、Double值是否小于0且大于255
添加DocumentListener to display overloading for JFormattedTextField
关于java - 在Java中的TextField中仅引入数字形成间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15272921/