drawing animations at the show of JDialog

By : hakan
Source: Stackoverflow.com

What would be the best way to draw a simple animation just before showing a modal JDialog? (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 setVisible method of the dialog.

However since the JDialog is modal to the parent, I couldn't find a way to pump drawing events into EDT before the JDialog becomes visible since the current event on the EDT has not been completed yet.

By : hakan


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. Here's a tutorial on creating animations on the Glass Pane.

Maybe you have a look at the SwingWorker Project which is included in JSE 6. (Link to SwingWorker) 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: http://filthyrichclients.org/

You may be able to take @rcreswick's answer and expand on it a little to make it work.

void myShowDialog() {
  new Thread(new Runnable() {public void run() {
    SwingUtilities.invokeAndWait(new Runnable() { public void run() {
    } } );
    // Delay to wait for the animation to finish (if needed)
    SwingUtilities.invokeAndWait(new Runnable() { public void run() {
    } } );
  } } ).start();

It's pretty ugly and would have to be invoked in place of the basic showDialog() call, but it should work.

This video can help you solving your question :)
By: admin