if (ae.getSource() == textID) {
textPSW.requestFocus();
} else if (ae.getSource() == textPSW) {
btnLogin.requestFocus();
}
这样只会聚焦到登录按钮上面,而不会真正的按下去!请问还要怎么办!!

解决方案 »

  1.   

    我用的是image 标签不用buttn 并且image标签比buttn要简单美观,直接上传漂亮的图片就行了,自动的有个回车提交。
      

  2.   

    在按钮上做一个键盘监听事件 然后对回车进行回应public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub
    if(e.getKeyCode() == KeyEvent.VK_ENTER)
    {
                        添加内容;
                    }
    }
      

  3.   

    import  javax.swing.*;  
      import  java.awt.event.*;  
        
      public  class  JMenuItem3e  extends  JFrame{  
        
      JTextArea  theArea  =  null;  
        
      public  JMenuItem3e(){  
            
          super("JMenuItem3e");  
          theArea  =  new  JTextArea();  
          theArea.setEditable(false);  
          getContentPane().add(new  JScrollPane(theArea));  
          JMenuBar  MBar  =  new  JMenuBar();  
          MBar.setOpaque(true);  
            
          JMenu  mfile  =  buildFileMenu();  
        
          MBar.add(mfile);      
          setJMenuBar(MBar);  
      }//end  of  JMenuItem3e()  
        
      public  JMenu  buildFileMenu()  {  
            
          JMenu  thefile  =  new  JMenu("File");  
          thefile.setMnemonic('F');  
        
          JMenuItem  newf  =  new  JMenuItem("New",new  ImageIcon("icons/new24.gif"));  
          JMenuItem  open  =  new  JMenuItem("Open",new  ImageIcon("icons/open24.gif"));  
          JMenuItem  close=  new  JMenuItem("Close",new  ImageIcon("icons/close24.gif"));          
          JMenuItem  quit  =  new  JMenuItem("Exit",new  ImageIcon("icons/exit24.gif"));  
        
          newf.setMnemonic('N');  
          open.setMnemonic('O');  
          close.setMnemonic('L');  
          quit.setMnemonic('X');  
            
          newf.setAccelerator(  KeyStroke.getKeyStroke('N',  java.awt.Event.CTRL_MASK,  false)  );  
          open.setAccelerator(  KeyStroke.getKeyStroke('O',  java.awt.Event.CTRL_MASK,  false)  );  
          close.setAccelerator(  KeyStroke.getKeyStroke('L',  java.awt.Event.CTRL_MASK,  false)  );  
          quit.setAccelerator(  KeyStroke.getKeyStroke('X',  java.awt.Event.CTRL_MASK,  false)  );  
        
          thefile.add(newf);      
          thefile.add(open);  
          thefile.add(close);                  
          thefile.addSeparator();  
          thefile.add(quit);  
        
          return  thefile;  
      }//end  of  buildFileMenu()  
        
      public  static  void  main(String[]  args){  
        
          JFrame  F  =  new  JMenuItem3e();  
          F.setSize(400,200);  
          F.addWindowListener(new  WindowAdapter()  {  
              public  void  windowClosing(WindowEvent  e)  {  
                  System.exit(0);    
              }  
          });//end  of  addWindowListener  
          F.setVisible(true);    
      }  //  end  of  main  
      }//end  of  class  JMenuItem3e