When performing a JavaFX animation I experience the animation freezes or stops running when the user decides to lock their screen (desktop). This occurs in Windows 7 via the (control alt delete) key combo. You don't even have to fully lock the screen just hit the ctrl alt delete to raise the prompt screen and hit the ESC (escape) key to return to desktop. You'll notice the JavaFX animation is halted.
Below is a simple animation moving a square indefinitely:
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Group root = new Group();
Rectangle rectangle = new Rectangle();
rectangle.setX(10);
rectangle.setY(10);
rectangle.setWidth(20);
rectangle.setHeight(20);
root.getChildren().addAll(rectangle);
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(1000), rectangle);
translateTransition.setFromX(10);
translateTransition.setToX(300);
translateTransition.setAutoReverse(true);
translateTransition.setCycleCount(TranslateTransition.INDEFINITE);
translateTransition.playFromStart();
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 350, 50));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}