【发布时间】:2018-03-01 10:48:05
【问题描述】:
我想为一个元素分配一个样式类。
我有一个 CSS:
.text-field{
-fx-background-color: #333333;
-fx-background-insets: 0 -1 -1 -1, 0 0 0 0, 0 -1 3 -1;
-fx-text-fill: white;
-fx-prompt-text-fill: white;
-fx-font-family: Trebuchet MS;
-fx-font-size: 14px;
}
.text-field:focused{
-fx-focus-color: white;
-fx-prompt-text-fill: white;
-fx-highlight-fill: grey ;
}
还有我正在使用的 java 代码:
JFXTextField textField = new JFXTextField();
textField.getStylesheets().add(this.getClass().getResource("/css/TextField_Style_Sheet.css").toExternalForm());
textField.getStyleClass().clear();
textField.getStyleClass().add("text-field");
我遇到的问题是 ":focused" 样式未应用于此元素。 我做错了什么?
已经在元素中直接使用场景构建器对其进行了测试,似乎“焦点颜色”和“非焦点颜色”选项中的设置覆盖了 text-field:focused 样式。 由于 JFXTextField 是在运行时创建的,因此默认的焦点颜色似乎覆盖了 css text-field:focused 样式。
如何解决?
【问题讨论】:
-
放在一边。在docs.oracle.com/javafx/2/api/javafx/scene/doc-files/… 中看不到任何
-fx-focus-color -
@Jean-BaptisteYunès 这是默认样式表中定义的查找颜色;它不是 CSS 属性,因此不在文档中。
标签: css javafx stylesheet