TextField passwordField = new TextField();
passwordField.setEchoChar('*');

解决方案 »

  1.   

    不好意思,是我没表达明白,不是做成PASSWORD,而是以定义的格式显示:
    比如说:2001-07-02....$300.45....
    或者规定其添入的数据类型...
    谁能解答,先谢喽,给分的!
      

  2.   

    给一个Date public class PaneJTextDate extends PlainDocument {
        public static String initString="####-##-##";
        private static int sep1=4, sep2=7;
        private static int month1=5,month2=6;
        private static int day1=8,day2=9;    private JTextComponent textComponent;
        private int newOffset;    public PaneJTextDate(JTextComponent tc) {
            textComponent=tc;
            try {
                insertString(0,initString,null);
            } catch (Exception ex) {}
        }    public void insertString(int offset,String s, AttributeSet attributeSet ) throws BadLocationException {
            int iTemp;
            if(s.equals(initString) ) {
                super.insertString(offset,s , attributeSet);
            } else {
                if(s.length()>1) {
                    if(s.length()!=10) return;
                } else {
                    try {
                        iTemp=Integer.parseInt(s);
                        if(offset==month1 || offset==month1-1)
                            if(iTemp>1) return;
                        if(offset==day1 || offset==day1-1)
                            if(iTemp>3) return;                } catch (Exception ex) {
                        return;
                    }
                }            newOffset=offset;
                if(atSeparator(offset)) {
                    newOffset++;
                    textComponent.setCaretPosition(newOffset);
                }
                super.remove(newOffset,s.length());
                super.insertString(newOffset,s,attributeSet);
            } // end if ( !=initString)
        } // end method insertString()    public void remove(int offset,int length) throws BadLocationException {
            if(atSeparator(offset)) {
                super.remove(offset-1,1);
                super.insertString(offset-1,"0",null);
                textComponent.setCaretPosition(offset-1);
            } else {
                super.remove(offset,1);
                super.insertString(offset,"0",null);
                textComponent.setCaretPosition(offset);
            }
        }//end method remove()    private boolean atSeparator(int offset) {
            return offset==sep1 || offset==sep2;
        }} // end class PaneJTextDate()
      

  3.   

    JTextField不能设定掩码,
    请使用JClass组件,可以轻松完成掩码的设置
      

  4.   

    to NoWant:
    非常感谢,激动,激动(不过还没试呢)
      

  5.   

    to 黑查理:
    JClass?能详细讲讲么?
      

  6.   

    呵,到这里下载一个看看demo可以了
    www.inprises.com,
    要我讲,给分先