如何动态更改javafx中滑块中的滑块拇指图标图像?

use*_*806 5 image slider javafx-2

在fxml文件中有滑块:

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

想要从我的.java类更改滑块拇指图标图像,因为我可以使用更改拇指图标图像 css

.slider .thumb{
 -fx-background-image :url("your image");   
 ...// more customization       
}
Run Code Online (Sandbox Code Playgroud)

但我想从.java类更改图像

请建议..

谢谢

Ser*_*nev 5

您可以使用Node#lookup()方法从Java代码中找到拇指.

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

StackPane thumb = (StackPane)slider.lookup(".thumb");
thumb.getChildren().clear();
thumb.getChildren().add(new ImageView(IMAGE));
Run Code Online (Sandbox Code Playgroud)

注意:请注意,您需要在stage.show()找到正确的查找后调用此代码.