开发者

JOptionPane.showOptionDialog does not always move to front in Applet

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_MESS开发者_StackOverflowAGE,
      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.


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 :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜