简体   繁体   中英

Focus listener in JTextField

如何在不使用TAB键的情况下将光标从JTextField1移至JTextField2如何使用FOCUS LISTENER进行此任务

No need to use the focus listener. Depending on what you code does, you may be able to use this:

field2.requestFocus();

"requestFocusInWindow()" is probably the Swing API you're looking for.

Here are several examples of several different "focus" related tasks:

Request Focus inside a Window

set Focus and all workaround isn't easy job in the most complex application, if is there attached DocumentListener or Jtextfield1/JTextField2 had already implemented FocusListene r that you have to wrap that inside invokeLater() your code for setFocus form/to should be

    Runnable doRun = new Runnable() {

        @Override
        public void run() {
            myTextField2.requestFocus();
            myTextField2.setText(myTextField2.getText());
            myTextField2.selectAll();
        }
    };
    SwingUtilities.invokeLater(doRun);

very complicated are if you needed move and set Focus betweens two or more Top-level Coantainers

field2.requestFocus(); ? or

public boolean requestFocusInWindow()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM