【发布时间】:2017-01-06 15:00:10
【问题描述】:
【问题讨论】:
【问题讨论】:
焦点边框颜色由-fx-focus-color和-fx-faint-focus-color两个CSS属性控制。
在大多数情况下,使用-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 伪类中的各种背景插入的背景颜色。因此对这个伪类的修改会影响焦点边框(例如边框的宽度)。
注意1:如果要完全去掉高亮,可以将这些属性设置为-fx-focus-color: transparent;。
注意 2:要对每个 Node 应用相同的高亮颜色,您可以在 CSS 文件中使用 .root { -fx-focus-color: red; } 类。
【讨论】:
.root { -fx-focus-color: red; }。但仅对于 TableView 仍不显示红色。其他节点如 Button、TextField 等都是红色的。有什么想法吗?
-fx-faint-focus-color 属性吗?
.table-view { -fx-background-insets: -3, 1, 2, 1; } 造成了麻烦。当我将其注释掉时,框架颜色变红了。但我真的需要设置彩色框架的厚度。你知道有什么其他方法可以让两个更厚的框架都变成红色吗?
.table-view:focused{ -fx-background-insets: -3, -2, 1; },因为在这个伪类中使用了这两个属性(您也可以在这个类中随意使用插图)。
.table-view:focused { -fx-faint-focus-color: red; -fx-background-insets: -3, 1, 2, 1; } 工作得很好!
感谢DVarga,我能够想出这个解决方案:
不知何故,-fx-focus-color: 无法与 -fx-background-insets: 组合使用 TableView 组件。
但是-fx-background-insets: 与-fx-faint-focus-color: 一起使用。因此,我的 css 解决方案如下所示:
.table-view:focused {
-fx-faint-focus-color: red;
-fx-background-insets: -3, 1, 2, 1;
}
现在它可以完美运行了!希望我们能帮助未来的你。
【讨论】: