-
Bug
-
Resolution: Fixed
-
P4
-
8u60, 9
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8148451 | 8u102 | Vadim Pakhnushev | P4 | Resolved | Fixed | b01 |
To reproduce, run the example
- move thumb between two ticks
- press button to enable snapToTicks
- expected: value (and with it the thumb) snapped to nearest tick
- actual: value/thumb unchanged, snapped at the next mouse touch only
Example:
public class SliderSnapToTickBug extends Application {
@Override
public void start(Stage primaryStage) {
Slider slider = new Slider(5, 25, 15);
// show ticks
slider.setShowTickMarks(true);
slider.setShowTickLabels(true);
slider.setMajorTickUnit(10);
Label valueLabel = new Label();
valueLabel.textProperty().bind(slider.valueProperty().asString());
Button snapTicks = new Button("snap to ticks");
snapTicks.setOnAction(e -> {
slider.setSnapToTicks(!slider.isSnapToTicks());
});
VBox root = new VBox(10, slider, valueLabel, snapTicks);
primaryStage.setScene(new Scene(root, 500, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Reason: SliderSkin doesn't listen to changes of the snapToTicks property
Fix: add listener and adjust value when changed to true
// in SliderSkin constructor
registerChangeListener(slider.snapToTicksProperty(), "SNAP_TO_TICKS");
// in handleControlProperty
} else if ("SNAP_TO_TICKS".equals(p)) {
if (slider.isSnapToTicks()) {
slider.adjustValue(slider.getValue());
}
}
the fix is without any risk and well bounded - so could be added at once :-)
- move thumb between two ticks
- press button to enable snapToTicks
- expected: value (and with it the thumb) snapped to nearest tick
- actual: value/thumb unchanged, snapped at the next mouse touch only
Example:
public class SliderSnapToTickBug extends Application {
@Override
public void start(Stage primaryStage) {
Slider slider = new Slider(5, 25, 15);
// show ticks
slider.setShowTickMarks(true);
slider.setShowTickLabels(true);
slider.setMajorTickUnit(10);
Label valueLabel = new Label();
valueLabel.textProperty().bind(slider.valueProperty().asString());
Button snapTicks = new Button("snap to ticks");
snapTicks.setOnAction(e -> {
slider.setSnapToTicks(!slider.isSnapToTicks());
});
VBox root = new VBox(10, slider, valueLabel, snapTicks);
primaryStage.setScene(new Scene(root, 500, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Reason: SliderSkin doesn't listen to changes of the snapToTicks property
Fix: add listener and adjust value when changed to true
// in SliderSkin constructor
registerChangeListener(slider.snapToTicksProperty(), "SNAP_TO_TICKS");
// in handleControlProperty
} else if ("SNAP_TO_TICKS".equals(p)) {
if (slider.isSnapToTicks()) {
slider.adjustValue(slider.getValue());
}
}
the fix is without any risk and well bounded - so could be added at once :-)
- backported by
-
JDK-8148451 Slider: snapToTicks not honoured on changing to true
-
- Resolved
-