获得焦点和失去焦点事件
我的 java swing 表单中有 4 个 JTextfield。问题是我需要通过 java 代码而不是使用 Tab 键将焦点从一个 JTextField 移动到另一个 JTextField。
如果JTextField2获得了Focus,则表示需要选择JTextField2中的内容。我不知道该怎么做,请将您正确的代码与此问题相关联
I have 4 JTextfields in my java swing form. The problem is I need to move the Focus from one JTextField to other through java code not by using tab key.
If the Focus gained by JTextField2 means the content in the JTextField2 need to be selected. I don't know how to do this plz put your proper code associate with this issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以调用
requestFocusInWindow ()
代表您想要焦点的文本字段。You can call
requestFocusInWindow()
for the textfield you want focus.这可能有点复杂,
您必须包装并延迟您的 Action 或 ActionListener 到
invokeLater()
,并放入其中(最安全的方法是设置以下代码行)JTextField2.setText(JTextField2.getText);
和
JTextField2.selectAll( );
编辑至@Andrew Thompson
that could be little bit complicated
you have to wrap and delay your Action or ActionListener into
invokeLater()
, and put inside (most safiest way is to set there follows code lines)JTextField2.setText(JTextField2.getText);
and
JTextField2.selectAll();
edit to @Andrew Thompson