我已经在FXML文件中创建了JFXListView:
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<JFXListView fx:id="listName" layoutX="-1.0" layoutY="-5.0" />
</children>
</AnchorPane>
并注入控制器
@FXML
private JFXListView<Label> listName;
然后我用标签填充JFXListView
public void loadListAdsTarget(){
listName.setVerticalGap(7.0);
for (int i = 0; i < 4; i++) {
listName.getItems().add(new Label("name " +i+ " desc : text text text"));
}
listName.getStyleClass().add("mylistview");
listName.depthProperty().set(1);
listName.setExpanded(true);
}
我试图通过css更改所选标签的颜色,但是将文本更改为白色并没有得到很好的结果。
.mylistview .label {
-fx-text-fill: #a0a2ab;
}
.mylistview:selected .label:selected {
-fx-text-fill: red;
}
.mylistview:focused .label:selected {
-fx-text-fill: while;
}
.mylistview .list-cell:selected {
-fx-background-color: #2196f3;
}
.mylistview .list-cell {
-fx-background-color: #282d40;
}
答案 0 :(得分:2)
将此部分CSS添加到您的文件中,它将更改所选文本的颜色
.mylistview .list-cell:selected .label{
-fx-text-fill: rgb(20, 20, 20);
}
您也可以删除此部分
.mylistview:focused .label:selected {
-fx-text-fill: while;
}