How do you set a focus on Textfield in Swing?

前端 未结 5 1291
名媛妹妹
名媛妹妹 2020-12-30 18:33

I have created one form using Swing in Java.In the form I have used one textfield on which I have to set the focus whenever I press the key.How to set focus on a particular

5条回答
  •  轮回少年
    2020-12-30 19:29

    This would work..

    SwingUtilities.invokeLater( new Runnable() { 
    
    public void run() { 
            Component.requestFocus(); 
        } 
    } );
    

提交回复
热议问题