a netbeans rcp blog

The basic of nodes part 2

Posted by Nicklas Löf on October 2, 2010

In my previous post I did go trough the very basic of nodes and we ended up with something that looks like this screenshot.

At the end I said that by looking at this screenshot there is probably two questions. Why is there an empty node with a white icon at the top? Why is the name repeated twice?

I will clarify this in this post which isn’t finished but will be shortly.

So lets start with the empty white node. Why is it there? To understand this we need to add one thing to our knowledge of nodes that I didn’t mention in the previous post but you might have understood it from some of the methods we called. First of all our NodeFactory did extend ChildFactory. Secondly we used a static method called Children.create. Do you see a common pattern?    Yes.. children!

Every single node that are created can have 0, 1 or many children. It’s a very simple thing but can be used to build folder structures of nodes. For example the Project tab in Netbeans or the File explorer. Those are nodes with children representing folders and files.

So the white icon node shown in the top is actually the node we created with this command.

em.setRootContext(new AbstractNode(Children.create(new CustomerNodeFactory(), true)));

It’s the AbstractNode which is our RootNode. When we are creating it we say that we are creating a Node that will contain children from our factory. Sometimes we want to show this node if we are showing a folder structure but in this case we don’t. So what can we do? We can’t remove the node since our Customers are children of the RootNode. Fortunately Netbeans Outlineview provides us with a simple method that hides the root node.


And boom. The root nodes is gone and we have a nice list of our customers.

So what can we do about the name that is repeated twice? The first column is actually a node column that always is visible. Remember that we did setPropertyColumns when we created the outlineview? If we hadn’t done that only the first colum would have been visible. But where does it get the name? If you look at the Customernode you will see that we did this:


So we could just remove that line and we will see only the icon in that column. We can also remove the name property from our setPropertyColumns() method call. So there is lot of possiblities and what you choose depends on the situation. Removing the display name works fine if you only are showing your nodes in this list but what if you want to show the same nodes in a tree folder view? Then the display name would be empty in that case.

I choose to remove the name column from my properties list:

outlineView.setPropertyColumns("type", "Type","contacted","Contacted");

That looks better doesn’t it? But wait..  now the colum for the company name isn’t Name anymore, it says Nodes now. We don’t want that. This can be solved easily by passing our desired column name to the outlineview when we are creating it.

outlineView = new OutlineView("Name");

And here we are done with part 2 of Nodes. I will add more parts showing how the icon can be customized, how we can add menu items to the menu that are shown when you right click on a node.


4 Responses to “The basic of nodes part 2”

  1. jnkjava said

    Hi Nicklas,

    nice useful post. I ‘ve been struggling with OutlineView quite some time now. The trick to get rid of the first column (‘Name’) was nice, but is there actually a way to get rid of the actual ‘Nodes’ column?

    Toni Epple ( has proposed this tip:
    but unfortunately it doesn’t work in 6.9.1 (as neither does this trick

    Looking forward your reply.

    • Lionel Lee said

      “but unfortunately it doesn’t work in 6.9.1 (as neither does this trick”

      According to my testing, removeColumn has to be implemented after setPropertyColumns.




      Outline outline = OutlineView.getOutline();

      TableColumn nodeColumn = outline.getColumnModel().getColumn(0);

    • Lionel Lee said

      Instead of using:

      TableColumn nodeColumn = outline.getColumnModel().getColumn(0);

      You may use:
      ETableColumnModel etcm = (ETableColumnModel) outline.getColumnModel();
      etcm.setColumnHidden((ETableColumn) etcm.getColumn(0), true);

      to hide the column from being displayed

  2. jkost said

    To get rid of the nodes column:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: