How to open a modal dialog in a Java applet?

I am trying to display a modal dialog before an Applet .

My current solution selects the root frame like this:

 Frame getMyParent() { Container parent = getParent(); while (!(parent instanceof Frame)) { parent = ((Component)parent).getParent(); } return (Frame)parent; } 

And will create a dialog as follows:

 public OptionsDialog(MainApplet applet, boolean modal) { super(applet.getMyParent(), "options", modal); // .... 

However, often this shows a modal dialog below the frame, although the modal behavior works correctly.

How can this be fixed?

Ideally, this should be for Java versions 1.5 and higher.

+7
java applet dialog
source share
3 answers
 JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this)); dialog.setModal(true); dialog.setSize(200, 200); dialog.setVisible(true); 
+4
source share

Frame f = (Frame) SwingUtilities.getAncestorOfClass (Frame.class, parentWindow); new JDialog (f, true);

(source = http://kb.trisugar.com/node/7613 ) works for parentWindow = sun.plugin2.main.client.PluginEmbeddedFrame

+3
source share

Use null insterad applet.getMyParent()

+2
source share

All Articles