如何在不使用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:
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.