Changing the colour of slider ticks

2019-07-04 05:22发布

问题:

I'm attempting to change the colour of the ticks for a slider in JavaFX 2.2, but coming up a bit short - I can't find any CSS properties on slider that claim to do this, and I can't find any methods on Slider that seem to do this either (there seems to be a property for formatting the tick labels, but not the marks themselves.)

Is there a way, or am I stuck drawing it myself?

回答1:

Use this style description for ticks and blue color :

.slider .axis .axis-tick-mark, .slider .axis .axis-minor-tick-mark {
    -fx-fill: null;
    -fx-stroke: blue;
}

The first - for major, the second - for minor.