java 如何更改 JavaFX 中的突出显示颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14126468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:09:46  来源:igfitidea点击:

How to change the highlighting color in JavaFX?

javacssjavafx-2javafx

提问by stetro

How to change the highlighting color in JavaFX? Usually it is blue with gradients, but I would like to have a green highlighting. I have tried the following:

如何更改 JavaFX 中的突出显示颜色?通常它是带有渐变的蓝色,但我想要绿色突出显示。我尝试了以下方法:

.root{
    -fx-shadow-highlight-color: #CCFF99;
}

Thanks for help!

感谢帮助!

回答by Uluk Biy

Look at caspian.css(JavaFX 2) or modena.css(JavaFX 8)

查看caspian.css(JavaFX 2) 或modena.css(JavaFX 8)

.root {
    /* A bright blue for highlighting/accenting objects.  For example: selected
     * text; selected items in menus, lists, trees, and tables; progress bars;
     * default buttons.
     */
    -fx-accent: #0093ff;

    /* A bright blue for the focus indicator of objects. Typically used as the
     * first color in -fx-background-color for the "focused" pseudo-class. Also
     * typically used with insets of -1.4 to provide a glowing effect.
     *
     * TODO: should this be derived from -fx-accent?
     */
    -fx-focus-color: #0093ff;
}

Change these colors according to their usages.

根据用途更改这些颜色。

回答by AbsoluteDev

I think Uluk Biy has answered it great way.

我认为 Uluk Biy 的回答很好。

But the reality is styling using CSS does not override the -fx-focus-color: #0093ff, rather it will overlap. If you use -fx-focus-color: red , it will get mixed with default blue color and show a shade of grey like color. The css attribute -fx-accent has no issues.

但实际情况是使用 CSS 的样式不会覆盖 -fx-focus-color: #0093ff,而是会重叠。如果您使用 -fx-focus-color: red ,它将与默认蓝色混合并显示类似灰色的阴影。css 属性 -fx-accent 没有问题。

回答by ivanjermakov

Also you can use -fx-highlight-fillon text-areaclass selector.

您也可以-fx-highlight-filltext-area类选择器上使用。

.text-area {
    -fx-highlight-fill: green;
}