Search code examples
cssjava-8javafx-8treetableview

Applying CSS on JavaFx TreeTableView fails


I'm trying to apply some CSS on JavaFx8 TreeTableView and when I run the application I get

Feb 04, 2015 9:13:24 AM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "font-size: 10px;" not found.

and here is the code I'm using:

private TreeItem<ZajelUser> root;
root = ...
TreeTableView<ZajelUser> treeTableView;
treeTableView = new TreeTableView<>(root);
treeTableView.getStylesheets().add("font-size: 10px;");
treeTableView.applyCss();

Solution

  • So there are two mistakes here:

    1. If you want to apply CSS styles directly, use Node.setStyle. Otherwise create a CSS file, write the rules there and attach the stylesheet with treeTableView.getStylesheets().add("myStyles.css;");
    2. You should change font-size: 10px; to -fx-font-size: 10px;.

    See the JavaFX CSS Reference Guide.