문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top