1

It's possible to set a LabelFormatter for JavaFX's very own Slider control, this allows one to define the text of the TickLabels freely. Unfortunately this doesn't seem possible with ControlsFX's RangeSlider control.

I was wondering whether this is still possible somehow or how it could be implemented manually?

underkuerbis
  • 325
  • 3
  • 9

1 Answers1

1

A workaround has been issued in the ControlsFX ticket system: https://bitbucket.org/controlsfx/controlsfx/issue/509/add-possibility-to-use-data-other-than

Implementing that workaround could look like this, make sure to implement your own StringConverter:

StringConverter<Number> rangeSliderLabelFormatter; // Implement a regular StringConverter to convert the values as needed.

rangeSlider.skinProperty().addListener(new ChangeListener<Skin<?>>() {
                @Override
                public void changed(ObservableValue<? extends Skin<?>> observable, Skin<?> oldValue, Skin<?> newValue) {
                    if (newValue != null) {
                        if (newValue instanceof RangeSliderSkin) {
                            RangeSliderSkin rangeSliderSkin = (RangeSliderSkin) newValue;
                            if (rangeSliderSkin.getChildren().get(0) instanceof NumberAxis) {
                                NumberAxis containedNumberAxis = (NumberAxis) rangeSliderSkin.getChildren().get(0);
                                containedNumberAxis.setTickLabelFormatter(rangeSliderLabelFormatter);
                            }
                        }
                    }
                }
            });
underkuerbis
  • 325
  • 3
  • 9