<p>What would be the best way to draw a simple animation just before showing a modal <a href="https://docs.oracle.com/javase/9/docs/api/javax/swing/JDialog.html" rel="nofollow noreferrer">JDialog</a>? (i.e. expanding borders from the mouse click point to the dialog location). I thought it would be possible to draw on the glasspane of the parent frame on the <code>setVisible</code> method of the dialog.</p>

<p>However, since the JDialog is modal to the parent, I couldn't find a way to pump drawing events into <a href="https://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html" rel="nofollow noreferrer">EDT</a> before the JDialog becomes visible, since the current event on the EDT has not been completed yet.</p>

[{'answer_id': 39868, 'author': 'rcreswick', 'author_id': 3446, 'author_profile': 'https://Stackoverflow.com/users/3446', 'pm_score': 1, 'selected': False, 'text': "<p>Are you trying to show the JDialog indepentently of the annimation? In order to get the order set properly, you may need to bundle those actions in a runnable that is passed to the EDT at once.</p>\n\n<p>eg:</p>\n\n<pre><code>SwingUtilities.invokeLater(new Runnable(){\n   public void run(){\n      doAnnimation();\n      showDialog();\n   }\n}\n</code></pre>\n\n<p>It may be best to subclass JDialog so that you can just add the doAnnimation() logic to the setVisible(..) or show() method before calling the superclass implementation.  </p>\n\n<p>Finally, I imagine you'll need to set the dimensions of the dalog manually --  I don't remember if Java will know the actual size of the dialog before it is shown, so you may get some useless information for your annimation if you query the size before showing it.</p>\n"}, {'answer_id': 42959, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 0, 'selected': False, 'text': "<p>You may be able to take @rcreswick's answer and expand on it a little to make it work.</p>\n\n<pre><code>void myShowDialog() {\n  new Thread(new Runnable() {public void run() {\n    SwingUtilities.invokeAndWait(new Runnable() { public void run() {\n      doAnimation();\n    } } );\n    // Delay to wait for the animation to finish (if needed)\n    Thread.sleep(500);\n    SwingUtilities.invokeAndWait(new Runnable() { public void run() {\n      showDialog();\n    } } );\n  } } ).start();\n}\n</code></pre>\n\n<p>It's pretty ugly and would have to be invoked in place of the basic showDialog() call, but it should work.  </p>\n"}, {'answer_id': 92610, 'author': 'Roland Schneider', 'author_id': 16515, 'author_profile': 'https://Stackoverflow.com/users/16515', 'pm_score': 1, 'selected': False, 'text': '<p>Maybe you have a look at the SwingWorker Project which is included in JSE 6. <a href="http://swingworker.dev.java.net/" rel="nofollow noreferrer">(Link to SwingWorker)</a> In the book "Filthy Rich Client" that I am reading at the moment they use this tool a lot. Maybe you can find a hint in the examples on the books website: <a href="http://filthyrichclients.org/" rel="nofollow noreferrer">http://filthyrichclients.org/</a></p>\n'}, {'answer_id': 3662376, 'author': 'Jay Askren', 'author_id': 240566, 'author_profile': 'https://Stackoverflow.com/users/240566', 'pm_score': 0, 'selected': False, 'text': '<p>One possibility is to paint your own dialog on the Glass Pane.  Then you have full control of the dialog and can paint whatever you want.  <a href="http://developerlife.com/tutorials/?p=16" rel="nofollow noreferrer">Here\'s a tutorial on creating animations</a> on the Glass Pane.</p>\n'}]
['https://Stackoverflow.com/questions/39108', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3993/']