Skip to main content

JXTreeTable - Highlighting rows

2 replies [Last post]
AspirinC
Offline
Joined: 2012-06-19

Hey everybody,

I've already searched quite long to find any tutorials on the Highlighters (because thats my closest guess on solving my problem) but I cant find any.

So thats what I want:
I have an JXTreeTable which I want to decorate.
The rows should have other colors for every hierachical stage.
(E.g. the top level is normal (white), the first folder with its children is red ... etc)
Additionally I want some Children to be colored and some not based on the TreeNode for this row.
And at last it would be great to color specific cells in a row.

Example:

Root
- Child 1 ( white row )
- Child 2 ( white row )
- Child 3 [Folder] ( red row )
-- Child 1 ( red row )
-- Child 2 ( white row, because child2 is an special object)
etc.

Hopefully this was understandable ;)
Would be great if you could give me some hints to archieve this.
Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

don't quite understand your concrete requirement, so just a quick comment: whether or not a Highlighter is used, is completely controlled by its HighlightPredicate. So your task boils down to implementing custom predicates, configure Highlighters with them and register the highlighters with the TreeTable.

SomeThing like

HighlightPredicate p1 = new HighlightPredicate() {
     public boolean isHighlighted(..., ComponentAdapter adapter ]
          // here comes the decision based on the adapter
     }
}
Highlighter h1 = new ColorHighlighter(p1, ....);
table.addHighlighter(hl);

There are examples in the test section of Swingx code and in the demo application, reachable at http://swinglabs-demos.java.net/demos/swingxset6/swingxset.jnlp

HTH
Jeanette

AspirinC
Offline
Joined: 2012-06-19

Thank you very much!
The "SomeThing like" Part helped me a lot :)