<p>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 <strong>all</strong> 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 <em>see</em> dialog on top of IE but it looks like it has hanged since it is not refreshe). </p>

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

<p>Here's the code:</p>

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

<p>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: </p>

<pre><code>parent = javax.swing.SwingUtilities.getWindowAncestor(theApplet);
</code></pre>

[{'answer_id': 73214, 'author': 'noah', 'author_id': 12034, 'author_profile': 'https://Stackoverflow.com/users/12034', 'pm_score': 0, 'selected': False, 'text': '<p>You might try launching a modal from JavaScript using the JavaScript integration (see <a href="http://www.raditha.com/java/mayscript.php" rel="nofollow noreferrer">http://www.raditha.com/java/mayscript.php</a> for an example). </p>\n\n<p>The JavaScript you would need would be something like:</p>\n\n<pre><code>function getPassword() {\n  return prompt("Enter Password");\n}\n</code></pre>\n\n<p>And the Java would be:</p>\n\n<pre><code>password = jso.call("getPassword", new String[0]);\n</code></pre>\n\n<p>Unfortunately that means giving up all hope of having a nice looking modal. Good luck!</p>\n'}, {'answer_id': 73525, 'author': 'James A. N. Stauffer', 'author_id': 6770, 'author_profile': 'https://Stackoverflow.com/users/6770', 'pm_score': 1, 'selected': False, 'text': '<p>Make a background Thread that calls toFront on the Dialog every 2 seconds.\nCode that we use (I hope I got everything):</p>\n\n<pre><code>class TestClass {\nprotected void toFrontTimer(JFrame frame) {\n    try {\n        bringToFrontTimer = new java.util.Timer();\n        bringToFrontTask = new BringToFrontTask(frame);\n        bringToFrontTimer.schedule( bringToFrontTask, 300, 300);\n    } catch (Throwable t) {\n        t.printStackTrace();\n    }\n}\n\nclass BringToFrontTask extends TimerTask {\n    private Frame frame;\n    public BringToFrontTask(Frame frame) {\n        this.frame = frame;\n    }\n    public void run()\n    {\n        if(count &lt; 2) {\n            frame.toFront();\n        } else {\n            cancel();\n        }\n        count ++;\n    }\n    private int count = 0;\n}\n\npublic void cleanup() {\n    if(bringToFrontTask != null) {\n        bringToFrontTask.cancel();\n        bringToFrontTask = null;\n    }\n    if(bringToFrontTimer != null) {\n        bringToFrontTimer = null;\n    }\n}\n\njava.util.Timer bringToFrontTimer = null;\njava.util.TimerTask bringToFrontTask = null;\n}\n</code></pre>\n'}, {'answer_id': 73615, 'author': 'Joel Anair', 'author_id': 7441, 'author_profile': 'https://Stackoverflow.com/users/7441', 'pm_score': 1, 'selected': False, 'text': "<p>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?</p>\n"}, {'answer_id': 93914, 'author': 'shemnon', 'author_id': 8020, 'author_profile': 'https://Stackoverflow.com/users/8020', 'pm_score': 2, 'selected': True, 'text': '<p>What argument are you using for the parent?</p>\n\n<p>You may have better luck if you use the parent of the Applet.</p>\n\n<pre><code>javax.swing.SwingUtilities.getWindowAncestor(theApplet)\n</code></pre>\n\n<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/73000', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7918/']