I am trying to animate a rectangle moving up and down on each button when the button is clicked like an indicator which button is active. But i don't like the idea of it just showing on each button as i had it done before i would like to animate it moving slowly from each button to another. So i tried doing it very simply bu changing the Y "coordinates" layout of the rectangle every 10mili seconds which would finally look like the rectangle is moving up or down depending on the for loop executed. But what happens is when a button is clicked there is longer wait time without the rectangle moving and then it appears on the place it is supposed to be at once. Looks like the Thread.sleep() is executed at once as much times as it should be and afterwards the setLayoutY() function is executed just once. Here is the code
public void moveRectangle(double newY) {
if (statisticsRectangle.getY() > newY)
for (double i = statisticsRectangle.getY(); i >= newY; i--) {
statisticsRectangle.setLayoutY(i);
try {
Thread.sleep(10);
}
catch (InterruptedException e){}
}
else
for (double i = statisticsRectangle.getY(); i <= newY; i++) {
statisticsRectangle.setLayoutY(i);
try{
Thread.sleep(10);
}
catch (InterruptedException e){}
}
}
public void addMemberButton() {
moveRectangle(60);
}