其实可以用掩码:
    JFrame f = new JFrame("JFormattedTextField Sample");
    Container content = f.getContentPane();
    MaskFormatter mf1 = 
    new MaskFormatter("#########");(用几个#号就可以输入几个数字)
    JFormattedTextField ftf2 = new JFormattedTextField(mf1);
    content.add(ftf2);
 这是一个办法。