JOptionPane.showOptionDialog 并不总是在 Applet 中移动到前面

发布于 2024-10-04 00:58:24 字数 477 浏览 1 评论 0原文

我的小程序中通常有一个 JOptionPane 弹出窗口,a-la:

      Object[] options = {"Grade", "Save", "Cancel"};
      selection = JOptionPane.showOptionDialog(this,
      "Do you want to grade now or save your work to continue later?",
      "Grade Or Save",
      JOptionPane.DEFAULT_OPTION,
      JOptionPane.QUESTION_MESSAGE,
      null, 
      options,
      options[2]);

this 指的是 JApplet 对象。

弹出窗口工作正常,一切正常,但有时它会出现在小程序后面,而不是弹出在小程序前面。

I have a JOptionPane popup in my applet normally, a-la:

      Object[] options = {"Grade", "Save", "Cancel"};
      selection = JOptionPane.showOptionDialog(this,
      "Do you want to grade now or save your work to continue later?",
      "Grade Or Save",
      JOptionPane.DEFAULT_OPTION,
      JOptionPane.QUESTION_MESSAGE,
      null, 
      options,
      options[2]);

this refers to the JApplet object.

The popup works fine and everything, but occasionally it will appear behind the applet instead of popping up in front of it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

茶底世界 2024-10-11 00:58:24

不知不觉中,您可能不会传入父组件;特别是“this”进入showOptionDialog()。确保“this”实际上是父组件。

如果“this”指的是一个框架,您可以通过执行以下操作找到焦点所在的框架:(

伪代码)

myFrames[] = Frame.getFrames();

if ( myFrames[i].isFocused() )
要传入的框架:)

Unknowingly you not may be passing in the parent component; specifically "this" into the showOptionDialog(). Make sure "this" is actually the parent component.

If "this" refers to a Frame you can find what frame is in focus by doing the following:

(pseduo code)

myFrames[] = Frame.getFrames();

if ( myFrames[i].isFocused() )
frame to pass in :)

迷你仙 2024-10-11 00:58:24

要做的事情是找到作为框架(它是隐藏的、插件特定类型)的小程序的父级,并使用该框架作为对话框所有者。您可以发现使用 (Frame)SwingUtilities.getAncestorOfClass(java.awt.Frame.class, theApplet);

这将确保对话框保留在浏览器顶部。但是,如果用户切换浏览器选项卡,该对话框不会隐藏。

The thing to do is find the parent of the applet that is a Frame (it's of a hidden, plugin specific type) and use that frame as the dialog owner. You can find that with (Frame)SwingUtilities.getAncestorOfClass(java.awt.Frame.class, theApplet);

That will ensure the dialog remains on top of the browser. However, if the user switches browser tabs, the dialog doesn't hide.

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