如何在 JOptionPane 之后请求FocusInWindow?
我有以下代码:
JOptionPane.showMessageDialog(this, "Wrong format!", "Wrong format!", JOptionPane.ERROR_MESSAGE);
myJTextField.requestFocusInWindow();
JTextField 在执行 JOptionPane 后没有获得焦点,如何以良好而干净的方式修复此问题?我的 JTextField 位于 JTabbedPane 上。
I have the following code:
JOptionPane.showMessageDialog(this, "Wrong format!", "Wrong format!", JOptionPane.ERROR_MESSAGE);
myJTextField.requestFocusInWindow();
The JTextField does not get focus after execution of JOptionPane, how do I fix this in a nice and clean way? My JTextField is on a JTabbedPane.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在两个
顶级容器
之间移动Focus
并不容易,因为Focus来自本机操作系统并且是异步的,您必须将此事件延迟到
invokeLater()
,如果没有成功,那么你必须寻找 Dialog聚焦,作者:@camickr
this isn't easy job move
Focus
betweens twoTop-Level Containers
, because Focus came from native OS and is asynchronous,you have to delay this event to the
invokeLater()
, if without success then you have to look for Dialog Focus by@camickr
showMessageDialog
会阻止 EDT,直到您确认对话框为止。因此,您设置焦点的代码行只有在对话框消失后才会运行。showMessageDialog
blocks the EDT until you have confirmed the dialog. So the line of code you have setting the focus won't run until after the dialog is gone.