I need to make an animated movement with my frame and it's inner panels.
While the user clicks on a specific inner panel (a panel which is inside frame) another panel is added to frame's contentPane
and then both, frame and new panel grow in width, but I always want my frame in the middle of screen. I solved the animation at this way:
Container container=getContentPane();
int i=0;
ActionListener run = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
frame.setSize(new Dimension(frame.getSize().width + 20, 550));
frame.setLocationRelativeTo(null);
//newp is the panel which is just added
newp.setPreferredSize(new Dimension(newp.getSize().width + 20, 550));
revalidate();
repaint();
container.revalidate();
container.repaint();
if (i > 20)
{
previousPanel = newp;
i = 0;
setInnerPanel(); // add another panel to added panel
container.revalidate();
container.repaint();
timer.stop();
}
i++;
}
};
timer = new Timer(15, run);
timer.setRepeats(true);
timer.start();
now there is an important problem. the animation is NOT smooth. i changed the timer delay to 20 and more but a good a smooth animation didn't come out...how to solve that?
Quick example, with variable duration...