JOptionPane.showOptionDialog 并不总是在 Applet 中移动到前面
我的小程序中通常有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知不觉中,您可能不会传入父组件;特别是“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 :)
要做的事情是找到作为框架(它是隐藏的、插件特定类型)的小程序的父级,并使用该框架作为对话框所有者。您可以发现使用
(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.