ADDITIONAL SYSTEM INFORMATION :
Java 1.8.0_144 on Redhat Linux 6.8, also OpenJDK 14.0.1 on Windows 7
A DESCRIPTION OF THE PROBLEM :
If either the increment/decrement arrows are pressed whilst a spinner is removed from the Scene it keeps going, even when it is added back to the Scene
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test app
2. (Within 10 seconds of window appearing) press and hold down mouse button on spinner increment button
3. Wait for spinner to be removed
4. Release mouse button
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Spinner should stop incrementing
ACTUAL -
Spinner is still incremented when added back to the scene
---------- BEGIN SOURCE ----------
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Duration;
public class SpinnerKeepsIncrementing extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Spinner<Double> spinner = new Spinner<>(0d, 1000d, 500d);
HBox container = new HBox(spinner);
primaryStage.setScene(new Scene(container));
primaryStage.show();
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(10), event -> {
container.getChildren().clear();
}));
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(15), event -> {
container.getChildren().setAll(spinner);
}));
timeline.play();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Following monkey patch can clear the error state
/**
* if we're holding down key on spinner whilst the cell changes bug in javaFX
* keeps firing update events.
*
* manually fire mouse released if decoupled from scene as workaround
*/
private void monkeyPatchSpinnerBug(Spinner<?> spinner) {
spinner.sceneProperty().addListener((obs, oldValue, newValue) -> {
Node increment = spinner.lookup(".increment-arrow-button");
if (increment != null) {
increment.getOnMouseReleased().handle(null);
}
Node decrement = spinner.lookup(".decrement-arrow-button");
if (decrement != null) {
decrement.getOnMouseReleased().handle(null);
}
});
}
FREQUENCY : always
Java 1.8.0_144 on Redhat Linux 6.8, also OpenJDK 14.0.1 on Windows 7
A DESCRIPTION OF THE PROBLEM :
If either the increment/decrement arrows are pressed whilst a spinner is removed from the Scene it keeps going, even when it is added back to the Scene
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test app
2. (Within 10 seconds of window appearing) press and hold down mouse button on spinner increment button
3. Wait for spinner to be removed
4. Release mouse button
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Spinner should stop incrementing
ACTUAL -
Spinner is still incremented when added back to the scene
---------- BEGIN SOURCE ----------
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Duration;
public class SpinnerKeepsIncrementing extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Spinner<Double> spinner = new Spinner<>(0d, 1000d, 500d);
HBox container = new HBox(spinner);
primaryStage.setScene(new Scene(container));
primaryStage.show();
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(10), event -> {
container.getChildren().clear();
}));
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(15), event -> {
container.getChildren().setAll(spinner);
}));
timeline.play();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Following monkey patch can clear the error state
/**
* if we're holding down key on spinner whilst the cell changes bug in javaFX
* keeps firing update events.
*
* manually fire mouse released if decoupled from scene as workaround
*/
private void monkeyPatchSpinnerBug(Spinner<?> spinner) {
spinner.sceneProperty().addListener((obs, oldValue, newValue) -> {
Node increment = spinner.lookup(".increment-arrow-button");
if (increment != null) {
increment.getOnMouseReleased().handle(null);
}
Node decrement = spinner.lookup(".decrement-arrow-button");
if (decrement != null) {
decrement.getOnMouseReleased().handle(null);
}
});
}
FREQUENCY : always