I have made an animation by changing the value of the horizontal scroll bar of a JScrollPane
, something like the transition between the screens of android OS. In the first seconds (up to 10 seconds) of running, if i ask for animation, it is not smooth and has jumping; but after a while that I play with that (ask for animation), it gets completely smooth. Why that happens and more important how to solve that?
I don't mean the first seconds of my animation is not smooth, I mean while I start my program the first times that I ask for animation that is not smooth but later, in the next times, that is smooth.
final JScrollBar br = mainContainerScrollPane.getHorizontalScrollBar();
ActionListener toTheRight = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
if (br.getValue() + 140 <= destinationScreenValue)
{
br.setValue(br.getValue() + 140);
} else
{
br.setValue(destinationScreenValue);
currentScreenName = destinationScreenName;
timer.stop();
}
}
};
timer = new Timer(10, toTheRight);
timer.setRepeats(true);
timer.setCoalesce(true);
timer.start();