, CSS. Skin, bar Node ImageView bar :
progress.BarBackgroundProgressBarSkin
public class BarBackgroundProgressBarSkin extends ProgressBarSkin {
public BarBackgroundProgressBarSkin(ProgressBar control) {
super(control);
}
private ImageView barBackground;
@Override
protected void initialize() {
super.initialize();
barBackground = new ImageView();
barBackground.setManaged(false);
barBackground.setPreserveRatio(false);
barBackground.getStyleClass().setAll("bar-background");
int barIndex;
List<Node> children = getChildren();
int size = children.size();
for (barIndex = 0; barIndex < size && !children.get(barIndex).getStyleClass().contains("bar"); barIndex++) {
}
Region bar = (Region) children.set(barIndex, barBackground);
barBackground.setClip(bar);
bar.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(2), new Insets(3, 3, 4, 3))));
}
@Override
protected void layoutChildren(double x, double y, double w, double h) {
barBackground.setLayoutX(x);
barBackground.setLayoutY(y);
barBackground.setFitHeight(h);
barBackground.setFitWidth(w);
super.layoutChildren(x, y, w, h);
}
}
style.css
.progress-bar {
-fx-skin: 'progress.BarBackgroundProgressBarSkin';
}
.progress-bar > .bar-background {
-fx-image: url('http://i.stack.imgur.com/glUAd.png');
}
.progress-bar > .track {
-fx-background-color: transparent;
}
Demo
@Override
public void start(Stage primaryStage) {
ProgressBar progressBar = new ProgressBar();
StackPane root = new StackPane();
root.getChildren().add(progressBar);
progressBar.setPrefSize(300, 18);
Scene scene = new Scene(root, 200, 200);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
Timeline tl = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(progressBar.progressProperty(), 0d)),
new KeyFrame(Duration.seconds(10), new KeyValue(progressBar.progressProperty(), 1d, Interpolator.EASE_OUT))
);
tl.setCycleCount(Animation.INDEFINITE);
tl.play();
primaryStage.setScene(scene);
primaryStage.show();
}