ListView Style in JavaFX

I have a list. I want to change the background color and fill in the text. I tried to do the following:

playlistView.setStyle("-fx-background-color: blue; -fx-text-fill: black;");

But that does not work. However, the following works:

playlistView.setStyle("-fx-font-size: 24px; -fx-font-family: 'SketchFlow Print';");

Could you tell me how to make the background and text fill? Thanks.

+4
source share
2 answers

You can use the following CSS styles:

.list-view .list-cell:even {
-fx-background-color: blue;
-fx-text-fill: black;
}
.list-view .list-cell:odd {
-fx-background-color: blue;
-fx-text-fill: black;
}
  • Save the contents of this style to lisStyles.css.
  • Add the stylesheet URL lisStyles.cssto the scene:

    scene.getStylesheets().add(getClass().getResource("lisStyles.css").toExternalForm());

+6
source

ListView, . . -fx-control-inner-background, "" , .

.list-cell {
    -fx-control-inner-background: blue ;
}

. , ( ), :

.list-cell {
    -fx-control-inner-background: blue ;
    -fx-control-inner-background-alt: derive(-fx-control-inner-background, 50%);
}

, , :

playlistView.setStyle("-fx-control-inner-background: blue;");

, ( ), .

+5

Source: https://habr.com/ru/post/1613979/


All Articles