JAVAFX 2.0 How can i change the slider icon in a slider to an image?


I want to change the icon to my image, I've looked through the CSS reference guide but I can't seem to find anything relevant. Is it even possible? Doesn't matter if it is using CSS or declaratively from main JavaFX script.

11/19/2012 4:02:30 PM

Take a look at the sample code and images of how a custom slider is rendered in this AudioPlayer.

Also the JFXtras library has numerous gauges if you just want feedback rather than an interactive control.

Here is some sample css using the selector pointed out by invariant's answer. Note that I needed to add an -fx-padding specification at half the images dimensions in order for the whole image to display.

/** slider.css
place in same directory as
ensure build system copies the css file to the build output path */

.slider .thumb {
    -fx-background-image :url("");   
    -fx-padding: 64;
/* Icon license: creative commons with attribution: */

Sample app:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;

public class SliderCss extends Application {
  public static void main(String[] args) { launch(args); }
  @Override public void start(Stage stage) throws Exception {
    VBox layout = new VBox();
    layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10px;");
    layout.getChildren().setAll(new Slider());
    stage.setScene(new Scene(layout));;

Sample program output:


11/19/2012 8:30:52 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow