JavaFX:样式组合框弹出列表文本颜色和所选项目颜色?

时间:2015-11-17 14:50:02

标签: css javafx combobox

我在css中使用样式ComboBox时遇到问题。我不知道如何更改所选项目fx的字体颜色(2人从黑色变为红色),以及如何在将鼠标指向当前选项时设置颜色效果。

css代码:

.combo-box
 {
  -fx-background-image:url("people_button.jpg");
  -fx-text-fill: red;
  -fx-min-width: 128;
  -fx-min-height: 48;

 }
.combo-box-popup .list-view
 {
   -fx-background-color: -fx-box-border, -fx-control-inner-background;
   -fx-background-insets: 0, 1;
   -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 8, 0.0 , 0 , 0 );
 }
.combo-box-popup .list-view .list-cell
 {
-fx-background-color: #ececec;
-fx-text-fill: #9a9a9a;
-fx-font-family: Oxygen Light;
 }

和java代码:

ComboBox<String> combo = new ComboBox();
combo.setVisibleRowCount(5);
combo.setItems(observableList);
combo.setValue("1 person");

enter image description here

1 个答案:

答案 0 :(得分:3)

只需将伪类hover添加到样式表:

.combo-box-popup .list-view .list-cell:hover {
    -fx-text-fill: red;
}

要为所选项添加颜色,请使用伪类selected

.combo-box .cell:selected {
    -fx-text-fill: red;
}
相关问题