因为要求不能使用JPasswordFiled,但是需要在JTextFiled中实现 输入信息后显示为"*",请问这部分代码要怎么写呢! 

解决方案 »

  1.   

    为什么不能用JPasswordField呢?JPasswordField本质上就是JTextField,也是继承自JTextField的,只不过不显示而已
    另外JPasswordField可以设置显示的符号,你想显示*号或#号,或任何其它符号都可以
      

  2.   

    我也没有办法啊!要求必须要使用的一个对方封好的控件是继承自JTextField,它有自动绑定数据库列的功能!而且不能被继承,现在要在这个基础上实现JPasswordField中的echoChar这个属性! 
      

  3.   

    貌似可以用 jTextField.setDocument(..)来解决setDocument(new PlainDocument(){
    StringBuilder sb=new StringBuilder();//用于存放字符内容
    public void insertString(int offs, String str, AttributeSet a)
    throws BadLocationException {
    sb.insert(offs,str);
    StringBuilder s=new StringBuilder(str);
    for(int i=0;i<s.length();i++)
    s.setCharAt(i,'#');//替换成回显字符
    super.insertString(offs,s.toString(),a);
    }
    public String getText(int offset, int length)
    throws BadLocationException {
    return sb.substring(offset,offset+length);//返回字符实际内容
    }
    public void remove(int offs, int len) throws BadLocationException {
    sb.delete(offs,offs+len);//删除
    super.remove(offs, len);
    }
    });
      

  4.   

    谢谢你!我去实验下!还有一个问题一直也没有解决掉!可否帮我也看一下呢!public   Collection   getDprcInfo(StringBuffer   permid,StringBuffer   begDt,StringBuffer   endDt)   throws   InterruptedException{ 
                    Collection   coll   =   new   ArrayList(); 
                    System.out.println("prel"); 
                    String   perlCmd   =   "C:/Scripts/get_sec_dprc_info.pl   --Permid   "+permid.toString()+"   --beg   "+begDt.toString()+"   --end   "+endDt.toString(); 
                    String   cmd   =   "C:\\cygwin\\bin\\bash.exe   -lc   \"perl   "+perlCmd+"   \"   "; 
                    System.out.println(cmd); 
                            Process   process; 
                            String   line; 
                  
                    try   { 
                            process   =   Runtime.getRuntime().exec(cmd);   
                            BufferedReader   prcout   =   new   BufferedReader( 
                            new   InputStreamReader( 
                            new   BufferedInputStream(process.getInputStream()))); 
                                                    while   ((line=prcout.readLine())   !=   null){ 
                                    coll.add(line);     
                                    process.waitFor(); 
                            }       prcout.close(); 
                                
                          
                    }   catch   (IOException   ex)   { 
                            ex.printStackTrace(); 
                    }               
                            return   coll;                       
            } 调用perl脚本!其中perl脚本是用来查询数据库中的满足条件的所有记录!当我输入日期后   需要将查询出的数据全部放在集合中!但 程序进行到while条件处   就不在继续,也不报错,也无异常!!!!!是否因为查询出数据量过大的原因呢! 我想是因为和缓冲有关的问题!但是一直都是没有解决掉!!
      

  5.   

    while循环都进不去!在readLine()方法这边就被卡住了!