[英]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. “ requestFocusInWindow()”可能是您正在寻找的Swing API。
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 在最复杂的应用程序中设置Focus
并进行所有变通并不是一件容易的事,如果附加了DocumentListener
或Jtextfield1/JTextField2
已经实现了FocusListene
r,则必须将其包装在invokeLater()
用于setFocus
form / to的代码应该是
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 如果您需要在两个或多个顶级协作者之间移动并设置Focus
则非常复杂
field2.requestFocus();
? ? or 要么
public boolean requestFocusInWindow()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.