简体   繁体   English

通过 css 更改 JavaFX 微调器

[英]changing JavaFX spinner via css

I am trying to change the style of the javafx spinner using a css stylesheet.我正在尝试使用 css 样式表更改 javafx 微调器的样式。

I know I can change the spinner button orientation via this code:我知道我可以通过以下代码更改微调按钮方向:

Spinner<Integer> spinner = new Spinner<Integer>(1, 20, 10);
            spinner.getStyleClass().add(split-arrows-horizontal);
            root.getChildren().add(spinner);

However, I want to achieve this via CSS or FXML.但是,我想通过 CSS 或 FXML 来实现这一点。 Does anybody know the solution有谁知道解决办法

You can easily create a Spinner like this using fxml:您可以使用 fxml 轻松创建这样的Spinner

<Spinner styleClass="split-arrows-horizontal">
    <valueFactory>
        <SpinnerValueFactory.IntegerSpinnerValueFactory min="1" max="20" initialValue="10" />
    </valueFactory>
</Spinner>

You could of course copy all the styles from modena.css containing .split-arrows-horizontal as part of it's selector and use all of them, even if this part of the selector does not apply, but this seems unnecessarily complicated compared with the approach posted above.您当然可以从modena.css中复制所有样式, modena.css包含.split-arrows-horizontal作为其选择器的一部分并使用所有样式,即使这部分选择器不适用,但与方法相比,这似乎不必要地复杂贴在上面。

Set the -fx-body-color that is used as background for the buttons:设置用作按钮背景的 -fx-body-color:

.spinner .increment-arrow-button,
.spinner .decrement-arrow-button {
    -fx-body-color: yellow;
}

.spinner .increment-arrow-button:hover,
.spinner .decrement-arrow-button:hover {
    /* interpolate color between yellow and red based on first color brightness */
    -fx-body-color: ladder(#444, yellow 0%, red 100%);
}

.spinner .increment-arrow-button:hover:pressed,
.spinner .decrement-arrow-button:hover:pressed,
.spinner .increment-arrow-button:pressed,
.spinner .decrement-arrow-button:pressed {
    /* interpolate color between yellow and red based on first color brightness */
    -fx-body-color: ladder(#AAA, yellow 0%, red 100%);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM