一応、そのコードで停止するように思えます。
「不必要なところは削除」とのことですが、逆に再現する短い完全なコードを載せた方が良いのではないでしょうか?
以下のようなコードを動かしてみてください。期待通りにTimelineが停止することが観察できると思います。
java
1public class TimelineTest extends Application {
2 Timeline timer;
3 int count = 0;
4 Label label;
5
6 @Override
7 public void start(Stage stage) throws Exception {
8 label = new Label("");
9 StackPane root = new StackPane(label);
10 root.setPrefSize(300, 100);
11 stage.setScene(new Scene(root));
12 stage.setTitle("Timeline test");
13 stage.show();
14
15 int speed = 10;
16 timer = new Timeline(new KeyFrame(Duration.millis(1000 / speed), event -> {
17 count++;
18 label.setText("" + count);
19 if (count >= 10) {
20 timer.stop();
21 }
22 }));
23 timer.setCycleCount(Timeline.INDEFINITE);
24 timer.play();
25 }
26}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。