Tweaking a TreeTableView

There's an interesting question at the end of yesterday's blog entry, by Kees Kuip, from the JMeld project, about text color and row color in org.openide.explorer.view.TreeTableView. How to set them? Well, you can create your own PropertyEditorSupport, as indicated below. The highlighted method is all I added to yesterday's code:

private class FullPathProperty extends PropertySupport.ReadOnly<String> {

    File file;

    public FullPathProperty(File file) {
        super(FileNode.PROP_FULL_PATH, String.class, "Full path", "Complete path is shown");
        this.file = file;

    public PropertyEditor getPropertyEditor() {
        return new FullPathPropertyEditor();

    public String getValue() throws IllegalAccessException, InvocationTargetException {
        return file.getAbsolutePath();


Then, you need to extend good old java.beans.PropertyEditorSupport. No NetBeans API magic at all. For example, now I have made the text in the "Full path" column red:

private class FullPathPropertyEditor extends PropertyEditorSupport {

    public String getAsText() {
        return (String) getValue();

    public void paintValue(Graphics g, Rectangle box) {
        g.drawString(getAsText(), box.x + 5, box.y + 15);

    public boolean isPaintable() {
        return true;


And this is the result:

You can use the paintValue method in many other ways, also to color the background of the cell. But that's all standard java.beans.PropertyEditorSupport stuff. To color alternate cells in the column, you could put an iterating number into a map whenever a new node is created. Then cycle through the map and make every odd numbered cell a distinct color. Probably you'd use isPaintable to determine whether a cell should be painted. You'd apply the same to the cells of the other columns in your table, as below:

Or some other similar solution. Also see Tim Boudreau's NetBeans Property Editor Tutorial for some interesting insights.


I thought i posted this before but i don't see my post. i am posting again. So my question is, in this example, you have one kind of node (FileNode) that represends a directory and a file. What if i have more than one kind of nodes in my tree, and i want to show different columns for different kinds of nodes. is that possible in a TreeTableView ?

Posted by hilz on October 07, 2007 at 12:11 PM PDT #

A very big thanks for this post.

It took me a while (and reading your code :-) ) that the only possible way of setting the tree column's name is to call setName on the root node.

Is there any way of making the tree column sortable?
I have the following code intended for the tree column:

public class MainDescriptionProperty extends PropertySupport.ReadOnly
private final String description;

public MainDescriptionProperty( String description )
super( "main_description", // property name
String.class, // property type
"Description", // header name -> seems that it is ignored if this property belongs to the tree column
"Description tooltip" // header tooltip
this.description = description;

this.setValue( "TreeColumnTTV", Boolean.TRUE ); // main tree column
this.setValue( "ComparableColumnTTV", Boolean.TRUE ); // sortable
this.setValue( "SortingColumnTTV", Boolean.FALSE ); // initially not sorted

public Object getValue() throws IllegalAccessException, InvocationTargetException
return description;

public PropertyEditor getPropertyEditor()
return null;

It puts the sorting arrow in the header, but does not do anything. Is there any way to apply sorting for this column, too?

Posted by Balazs on October 08, 2007 at 12:29 AM PDT #

hilz, hope my blog today answers at least part of your question.

Balazs, hi! How are you assigning the above propert support to the tree column? I mean how/where are you instantiating it?

Posted by Geertjan on October 08, 2007 at 04:07 AM PDT #

Balazs, I tried to show how to make the tree column sortable, in the next blog entry.

Posted by Geertjan on October 08, 2007 at 09:13 AM PDT #

I'm using a PropertyEditorSupport that supports a customSupportEditor. On my custom editor, the OK button behaves like d CANCEL button and vice-versa. This is driving me crazy. Is there a solution for this.

Posted by Joseph on August 18, 2010 at 06:31 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014