Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top