- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人能帮帮我吗……我已经尝试了各种方法(包括此处的帮助),但还是行不通。我将 JFormattedTextField 与 MaskFormatter 一起使用,以将数据输入限制为 4(最大)位数字。
static JFormattedTextField textPayout;
MaskFormatter f;
try {
f = new MaskFormatter("####");
} catch (ParseException e) {
e.printStackTrace();
return; // actual code not written yet.
}
textPayout = new JFormattedTextField(f);
问题是它既不限制字符也不限制长度(另外,如果输入非数字,文本开始重叠)。而且我已经尝试了各种各样的类似面具的操作。有人可以告诉我我做错了什么吗?
谢谢
最佳答案
我刚刚尝试了这段代码,它运行良好,但有一个小问题:
class A extends JFrame {
public static void main(String args[]) throws ParseException {
A a = new A();
a.setLayout(new GridLayout());
JFormattedTextField textField =
new JFormattedTextField(new MaskFormatter("####"));
a.add(textField);
a.add(new JButton("qwe"));
a.setSize(300,50);
a.setVisible(true);
}
}
问题是最初出现的文本字段充满了 4 个空格,所以我不得不删除它们。可能这就是 Gentoo 编译的 IcedTea 7.2 的怪异之处。
否则一切正常,你能试试我的代码吗,如果它不起作用那么你的 Java 版本是多少?
关于Java-MaskFormatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9344321/
有人能帮帮我吗……我已经尝试了各种方法(包括此处的帮助),但还是行不通。我将 JFormattedTextField 与 MaskFormatter 一起使用,以将数据输入限制为 4(最大)位数字。
我正在尝试将 MaskFormatter 与 JFormattedTextField 一起使用。 在我的类(class)中我有这行代码 JFormattedTextField jtfCNP=new J
我正在尝试制作一个设置为接受 float 的文本字段,并且我为此使用了正则表达式。我遇到了问题,因为当我输入数字时,例如 12345.67 然后当我尝试删除输入时,我无法删除数字 1.. 为什么?>
我想将输入限制为 JFormattedTextField,并且我有一个使用 MaskFormatter 的设置。 但是,我必须输入指定的字符数(在本例中为 5)。有没有办法让它接受任何大小的输入,并且
我是 Swing Java 开发的新手。有人可以帮我解决这个问题吗。 我有一个带有 maskformatter 的 jformattedtextfield。它工作得很好。但我唯一想知道的是我们是否可以
我有一个 JFormattedTextField 用于限制日期和时间的输入。我想使用 MaskFormatter 来显示占位符字符。当文本字段已经在使用 SimpleDateFormat 时,是否可以
我为我的jFormattedTextField创建了一种格式 MaskFormatter formatter = new MaskFormatter("###.###.###.###"); forma
所以我有一个 JFormattedTextField,我需要限制用户输入除字母和连字符以外的任何内容。在没有明确知道要输入的字符串的长度的情况下,我不太确定如何使用 MaskFormatter。 我的
我使用以下代码在我的 JFormattedTextField 上应用 MaskFormatter,以使其接受 IBAN(2 个字母后跟 20 个数字): MaskFormatter formatter
在你对我嗤之以鼻之前,请记住你们每个人都是从某个时候开始的(之所以这么说是因为我看到了回复)。是的,我正在学习,但需要一些帮助来了解 DocumentFilter、KeyListener 或任何其他仅
我需要一个 JFormattedTextField 只允许输入 ##-###** 其中连字符始终出现在文本字段中,最后一个2 个字符,由 * 表示,可以是 2 个字母表 (a-z/A-Z),也可以什么
使用Java swing,使用 MaskFormatter 时对应于正确电子邮件掩码的字符串是什么? ?是否有可能实际使用 MaskFormatter 来发送电子邮件? 最佳答案 尽管使用 MaskF
在将 MaskFormatter 应用到 JFormattedTextField 上,然后将该文本字段设置为我的 JTable 中的列后,插入符号开始出现在我单击的任何位置。但是,我希望插入符号出现在
看完this article和 this question我试图将两者结合起来:JFormattedTextField,它始终在正确的位置显示斜杠,并自动解析 Date 对象。 我想出的代码如下: p
我想将 jxdatepicker 与 maskFormatter 一起使用。我试过了 MaskFormatter maskFormatter = new MaskFormatter ("##/##/#
我有一个函数,我需要将字符串设置为以下格式:#####-####-## 并用前导零填充。 例如:1234567 将变成 00001-2345-6798765432109 将变成 98765-4321-
////DOB column formats to dd/mm/yy TableColumn dobColumn = table.getColumnModel().getColumn(3);
我有一个使用以下掩码格式化程序的 JFormattedTextField: private MaskFormatter maskForInput; maskForInput=new M
我是一名优秀的程序员,十分优秀!