Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing animations at the show of a JDialog

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.

like image 657
hakan Avatar asked Nov 05 '22 23:11

hakan


2 Answers

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.

eg:

SwingUtilities.invokeLater(new Runnable(){
   public void run(){
      doAnnimation();
      showDialog();
   }
}

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.

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.

like image 53
rcreswick Avatar answered Nov 12 '22 11:11

rcreswick


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/

like image 41
Roland Schneider Avatar answered Nov 12 '22 11:11

Roland Schneider