JavaFX slider to change width (thickness)

My problem is that the default slider is too thin

Thank you for your advice

Solution

In JavaFX, most styles can be done through CSS

You can use it in CSS files slider . Track and slider . Thumb style class In this style class, you can use the - FX pref width and - FX pref height attributes:

.slider .track {
    -fx-pref-height:20;
}

.slider:vertical .track {
    -fx-pref-width:20;
}

.slider .thumb {
    -fx-pref-height: 30;
    -fx-pref-width: 30;
}

Alternatively, you can use the - FX padding attribute:

.slider .track {
    -fx-padding: 10;
}

.slider .thumb {
    -fx-padding: 15;
}

This will generate horizontal and vertical sliders like this:

In any case, you can refer to JavaFX 8 default stylesheet (Modena. CSS) and JavaFX CSS reference guide

You can also use official tutorial about using CSS to set JavaFX styles

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>