Modal dialogs in IE gets hidden behind IE if user clicks on IE pane

左心房为你撑大大i 提交于 2019-12-06 05:52:43

What argument are you using for the parent?

You may have better luck if you use the parent of the Applet.

javax.swing.SwingUtilities.getWindowAncestor(theApplet)

Using the getWindowAncestor will skip the applet parents (getRoot(component) will return applets). In at least some versions of Java there was a Frame that was equivalent to the IE window. YMMV.

Make a background Thread that calls toFront on the Dialog every 2 seconds. Code that we use (I hope I got everything):

class TestClass {
protected void toFrontTimer(JFrame frame) {
    try {
        bringToFrontTimer = new java.util.Timer();
        bringToFrontTask = new BringToFrontTask(frame);
        bringToFrontTimer.schedule( bringToFrontTask, 300, 300);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

class BringToFrontTask extends TimerTask {
    private Frame frame;
    public BringToFrontTask(Frame frame) {
        this.frame = frame;
    }
    public void run()
    {
        if(count < 2) {
            frame.toFront();
        } else {
            cancel();
        }
        count ++;
    }
    private int count = 0;
}

public void cleanup() {
    if(bringToFrontTask != null) {
        bringToFrontTask.cancel();
        bringToFrontTask = null;
    }
    if(bringToFrontTimer != null) {
        bringToFrontTimer = null;
    }
}

java.util.Timer bringToFrontTimer = null;
java.util.TimerTask bringToFrontTask = null;
}

This is a shot in the dark as I'm not familiar with applets, but you could take a look at IE's built-in window.showModalDialog method. It's fairly easy to use. Maybe a combination of this and Noah's suggestion?

You might try launching a modal from JavaScript using the JavaScript integration (see http://www.raditha.com/java/mayscript.php for an example).

The JavaScript you would need would be something like:

function getPassword() {
  return prompt("Enter Password");
}

And the Java would be:

password = jso.call("getPassword", new String[0]);

Unfortunately that means giving up all hope of having a nice looking modal. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!