How to open a modal dialog in Java applet?
I'm trying to display a modal dialog in front of an Applet
.
My current solution fetc开发者_JS百科hes the root frame like so:
Frame getMyParent() {
Container parent = getParent();
while (!(parent instanceof Frame)) {
parent = ((Component)parent).getParent();
}
return (Frame)parent;
}
And creates the dialog as follows:
public OptionsDialog(MainApplet applet, boolean modal) {
super(applet.getMyParent(), "options", modal);
// ....
However often this shows the modal dialog below the frame, though the modal behaviour works correctly.
How can this be fixed?
Ideally this should be for Java versions 1.5 and above.
JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this));
dialog.setModal(true);
dialog.setSize(200, 200);
dialog.setVisible(true);
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
Use null insterad of applet.getMyParent()
精彩评论