Original report by jonathan millman (Bitbucket: millmanorama, GitHub: millmanorama).
because RangeSliderSkin does not use a mouseReleasedHandler, it sets both isLow/HighChanging to false for every drag gesture, and there is no way to detect finalized input.
I have fixed this in my client code temporarily by overriding the mouse handlers:
#!java
private void attachDragListener(RangeSliderSkin skin) {
if (skin != null) {
for (Node n : skin.getChildren()) {
if (n.getStyleClass().contains("range-bar")) {
StackPane rangeBar = (StackPane) n;
rangeBar.setOnMousePressed((MouseEvent e) -> {
rangeBar.requestFocus();
preDragPos = e.getX();
});
rangeBar.setOnMouseReleased((MouseEvent event) -> {
rangeSlider.setLowValueChanging(false);
rangeSlider.setHighValueChanging(false);
});
rangeBar.setOnMouseDragged((MouseEvent event) -> {
final double min = rangeSlider.getMin();
final double max = rangeSlider.getMax();
///!!! compensate for range and width so that rangebar actualy stays with the slider
double delta = (event.getX() - preDragPos) * (max - min) / rangeSlider.
getWidth();
////////////////////////////////////////////////////
final double lowValue = rangeSlider.getLowValue();
final double newLowValue = Math.min(Math.max(min, lowValue + delta),
max);
final double highValue = rangeSlider.getHighValue();
final double newHighValue = Math.min(Math.max(min, highValue + delta),
max);
if (newLowValue <= min || newHighValue >= max) {
return;
}
rangeSlider.setLowValueChanging(true);
rangeSlider.setHighValueChanging(true);
rangeSlider.setLowValue(newLowValue);
rangeSlider.setHighValue(newHighValue);
});
}
}
}
}
this should be easy to incorporate back into ControlsFX, but i don't know if I will have the time.
该提问来源于开源项目:controlsfx/controlsfx