Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple way to change JavaFX treeview background and text color

This seems like something crazy simple, I'm new with JavaFX, and I cannot change the background and text color of JavaFX TreeView (added inside of a GridPane). Ive initialized the treeview constructor with the root node of populated treeitem.

in the .css:

.myTree {
   -fx-font: 12px Tahoma;
   -fx-stroke: #eeeeee;
   -fx-background-color: #0a0a0a;
   -fx-text-fill: #ffffff;
   }

and in the code

 treeView.getStyleClass().add("myTree"); 

the font sets, but nothing else. I cant seem to find any example of anyone changing the background of treeview - lots of doing fancy changes on select and hover. Any ideas ?

like image 575
thefog Avatar asked Mar 23 '15 21:03

thefog


2 Answers

Set the background color on the cells:

.myTree .tree-cell {
    -fx-background-color: #0a0a0a ;
    -fx-text-fill: #ffffff ;
}
like image 142
James_D Avatar answered Sep 28 '22 09:09

James_D


If you just want a simple way to get away from the yucky white tree background color, you can do this in the scene builder.

  1. Place a "region" over the tree view. This will resize correctly.
  2. Make sure the region is on top (send to front).
  3. Set the regions's color. (a dark color, i.e. blue).
    i. Use -fx-background-color : darkblue
  4. Set opacity to about 0.15
  5. Set mouseTransparency to true.
  6. Done!
like image 28
Alf Avatar answered Sep 28 '22 09:09

Alf