betaman
betaman

Reputation: 1895

JavaFX2: What is the best way to style an individual TreeItem?

I would have liked to have the ability to add a CSS class to the TreeItem and then just use a CSS file to give it style. But that is not possible, or is it?

Is there a way to add a class like we can using getStyleClass()?

If not, what is the best way to give individual items a style?

Upvotes: 0

Views: 2515

Answers (3)

user507484
user507484

Reputation:

Use a TreeCellFactory , and in the factory, use a Node and set it's style, either via getStyle, or even better via Node.setStyleClass.

Upvotes: 1

Bruno Vieira
Bruno Vieira

Reputation: 3904

Well... Think outside the box! You can't style treeitem and tablerow because they act basically as a form of containers to other nodes, so set a class for the nodes on your treeitem (or tablerow) and then style them. I'm sorry by the answer, but I can't add comments yet

Upvotes: 1

Zookey
Zookey

Reputation: 2707

Best way to give style to items is use of stylesheets, limit use of Node.setStyle.

You may wonder why?

Reason is a performance. Calculate style values are cached. All Nodes that match the same selectors can share the calculculate value.

Upvotes: 1

Related Questions