怎样将(用JFormattedTextField,并用过滤器阻止非数字格式输入的)文本框里面显示的数字的那些逗号去掉???
具体代码如下:
JFormattedTextField userIdText= new JFormattedTextField(new
InternationalFormatter(NumberFormat.getIntegerInstance())
{
private DocumentFilter filter = new IntFilter();
protected DocumentFilter getDocumentFilter()
{
return filter;
}
});
......
class IntFilter extends DocumentFilter
{.......}
这样用了以后阻止了非数字的输入,但是只要一过三位数就出来那个讨厌的逗号,没法直接用Integer转化了,求教!
问题点数:20、回复次数:2Top
1 楼Z_Beginner(探索中)回复于 2005-02-08 03:57:30 得分 20
其实可以用掩码:
JFrame f = new JFrame("JFormattedTextField Sample");
Container content = f.getContentPane();
MaskFormatter mf1 =
new MaskFormatter("#########");(用几个#号就可以输入几个数字)
JFormattedTextField ftf2 = new JFormattedTextField(mf1);
content.add(ftf2);
这是一个办法。Top
2 楼angues1980(石头心)(JSF学习中)回复于 2005-02-08 09:05:53 得分 0
离我的想法还差一点点,如果这样做的话,
用户必须输入我指定的位数的数字,数据才会被接受啊Top




