最佳答案
焦点边框着色由两个 CSS 属性 -fx-focus-color
和 -fx-faint-focus-color
控制。
在大多数情况下,使用 -fx-focus-color
就足够了,例如将此类添加到您的 CSS 文件中:
.table-view {
-fx-focus-color: red;
}
或直接在 Java 代码中:
table.setStyle("-fx-focus-color: red;");
但你也可以像这样覆盖两者:
.table-view {
-fx-focus-color: red;
-fx-faint-focus-color: white;
}
背景:
通过检查默认样式表 modena.css:
.table-view:focused{
-fx-background-color: -fx-faint-focus-color, -fx-focus-color, -fx-control-inner-background;
-fx-background-insets: -1.4, -0.3, 1;
-fx-background-radius: 2, 0, 0;
}
它发现这些颜色在 :focused
伪类中被用作具有各种 background-insets 的背景颜色。因此对该伪类的修改会影响焦点边框(例如边框的宽度)。
注意1:如果你想完全去除高亮,你可以将这些属性设置为-fx-focus-color: transparent;
。
注意 2: 要对每个 Node
应用相同的高亮颜色,您可以使用 .root { -fx-focus-color: red;
CSS 文件中的类。
关于java - 如何更改 JavaFX 中的 TableView 框架颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39225569/