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!