如何在 JOptionPane 之后请求FocusInWindow?

发布于 2024-12-20 08:09:36 字数 269 浏览 5 评论 0原文

我有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江城子 2024-12-27 08:09:36

在两个顶级容器之间移动Focus并不容易,因为Focus来自本机操作系统并且是异步的,

您必须将此事件延迟到invokeLater(),如果没有成功,那么你必须寻找 Dialog聚焦,作者:@camickr

this isn't easy job move Focus betweens two Top-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

ι不睡觉的鱼゛ 2024-12-27 08:09:36

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文