How can I dynamically change the thumbnail image of a slider thumb in a slider in javafx?

There is a slider in the fxml file:

Slider fx: id = "slider" minHeight = "20" minWidth = "- Infinity" prefWidth = "300.0"

Want a thumb slider image that needs to be resized from my .java class as I can change the thumb icon image with css

.slider .thumb{
 -fx-background-image :url("your image");   
 ...// more customization       
}

But I want to change the image from the .java class

Please suggest ..

thank

+5
source share
1 answer

You can find your thumb with Java code using the Node #lookup () method .

String IMAGE = getClass().getResource("my-image.png").toExternalForm();

StackPane thumb = (StackPane)slider.lookup(".thumb");
thumb.getChildren().clear();
thumb.getChildren().add(new ImageView(IMAGE));

N.B.: , stage.show(), .

+4

All Articles