JavaFX2: What is the best way to style an individu

2019-06-10 04:19发布

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?

3条回答
▲ chillily
2楼-- · 2019-06-10 04:53

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.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-10 05:00

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

查看更多
疯言疯语
4楼-- · 2019-06-10 05:08

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

查看更多
登录 后发表回答