I want to place the selected value of a Slider
on top of its thumb
:
I have entered the following code:
miSlider.valueProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
información.textProperty().setValue(
String.valueOf((int) miSlider.getValue()));
// posiciono la información
información.setPadding(new Insets(0,0,0,
(miSlider.getValue() - miSlider.getMax()) * miSlider.getWidth() /
(miSlider.getMax()-miSlider.getMin()) + miSlider.getWidth() ));
}
});
The Label
info is not placed right above the thumb
. How do I get the position of the thumb
?
Use
getBoundsInParent()
andlookUp()
:You will need to apply
CSS
theSlider
withapplyCss()
beforelookUp
for the position to display correctly.This answer is a translation of the answer you have in this link along with an example: https://stackoverflow.com/questions/38131485/coordinates-of-slider-thumb-in-javafx