JavaFX ProgressBar: how to change bar color?

前端 未结 2 537
别跟我提以往
别跟我提以往 2020-12-03 21:43

I\'m trying to change the color of bar in ProgressBar with

pBar.setStyle(\"-fx-accent: green\");

but I have encountered a problem: that doe

2条回答
  •  天命终不由人
    2020-12-03 22:16

    You should to override (or customize) the style with JavaFX CSS selectors. See caspian.css for more information. In your own stylesheet define:

    .progress-bar .bar {
        -fx-background-color:
            -fx-box-border,
            linear-gradient(to bottom, derive(-fx-accent,95%), derive(-fx-accent,10%)),
            red; /* this line is the background color of the bar */
        -fx-background-insets: 0, 1, 2;
        -fx-padding: 0.416667em; /* 5 */
    }
    

提交回复
热议问题