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

时光毁灭记忆、已成空白 提交于 2019-12-08 01:20:16

问题


I have to write an applet that brings up a password dialog. The problem is that dialog is set to be always on top but when user clicks on IE window dialog gets hidden behind IE window nevertheless. And since dialog is modal and holds all IE threads IE pane does not refresh and dialog window is still painted on top of IE (but not refreshed). This behaviour confuses users (they see dialog on top of IE but it looks like it has hanged since it is not refreshe).

So I need a way to keep that dialog on top of everything. But any other solution to this problem would be nice.

Here's the code:

        PassDialog dialog = new PassDialog(parent);
        /* do some non gui related initialization */
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setAlwaysOnTop(true);
        dialog.setVisible(true);

Resolution: As @shemnon noted I should make a window instead of (null, Frame, Applet) parent of modal dialog. So good way to initlialize parent was:

parent = javax.swing.SwingUtilities.getWindowAncestor(theApplet);

回答1:


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.




回答2:


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;
}



回答3:


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?




回答4:


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!



来源:https://stackoverflow.com/questions/73000/modal-dialogs-in-ie-gets-hidden-behind-ie-if-user-clicks-on-ie-pane

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