ninja007
ninja007

Reputation: 53

how tp set the different font fill text color for selected label in a JFXListView?

I've create a JFXListView in th FXML file :

<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>

and injected in controller

@FXML
private JFXListView<Label> listName;

then I fill the JFXListView with labels

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);
}

I tried to change the color of the selected label by css, but I did not get a good result by changing the text to white.

.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;
}

enter image description here

Upvotes: 0

Views: 255

Answers (1)

Matt
Matt

Reputation: 3187

Add this section of css to your file and it will change the selected text color

.mylistview .list-cell:selected .label{
    -fx-text-fill: rgb(20, 20, 20);
}

You can also remove this section

.mylistview:focused .label:selected {
    -fx-text-fill: while;
}

Upvotes: 2

Related Questions