Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

animating a JFrame resize...

843806Jun 7 2007 — edited Jun 7 2007
I have a function that requires to make the current JFrame to be resized vertically (larger). I'd like to animate the frame's resizing like i've seen on some programs or websites (ie like pulling down a blind and the new gui components below are now revealed).

here's a method i've played with, but the result isn't very consistent, let alone smooth. i suspect a problem with threads, but i have always sucked at using swing threads... any help would be greatly appreciated. the method is a part of a class that extends the JFrame class.

void animateOpen(int finalH, double interval, double secs, int startH)
    {
        new SwingWorker() 
        {
          public Object construct() 
          {  
            setVisible(true);
            return null;
          }
        }.start();
       

       for (int i = 0; i < (int)(secs / interval); i++)
       {
           interimHeight = startH + (int)((double)(i+1)*(double)(finalH - startH)*(interval/secs));
           cout(i + " --> " + height);
           c.setPreferredSize(new Dimension(prefW, interimHeight ));
           pack();
       }
       c.setPreferredSize(new Dimension(prefW, prefH));
       pack();
    }
the algorithm produces the intended animation, ie changes the preferredSize as intended, but it does it choppily and different with each execution. sometimes its smooth, sometimes it appears full size with no animation, and sometimes it falls short and stops halfway.

how to i fix these problems?

thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2007
Added on Jun 7 2007
3 comments
347 views