开发者

How to open a modal dialog in Java applet?

开发者 https://www.devze.com 2023-01-20 03:56 出处:网络
I\'m trying to display a modal dialog in front of an Applet. My current solution fetc开发者_JS百科hes the root frame like so:

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

0

精彩评论

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

关注公众号