tags:

views:

179

answers:

1

I am working with a JTreeTable as described in an old article at: Sun Developer Network

Here are the same files but slightly adjusted for java 6: http://edtaylor80.angelfire.com

If you run this little example program you will find that selection works as expected to start with, entire rows are selected when you click a random cell. This behaviour is desired. However, as soon as a node is expanded the behaviour changes, now it is only possible to select a row by clicking at the actucal node (name). I still want to be able to select an entire row by clicking a random cell. How can I modify the source code to accomplish this?

+1  A: 

Before you click into the first column to open a node, there is no cell editor for the JTable. Once you perform that operation, the table has an active cell editor, which is an instance of the AbstractCellEditor that comes as part of the JTreeTable example source. In the implementation therein, you will find this:

public boolean shouldSelectCell(EventObject anEvent) { return false; }

This gets called by the BasicTableUI when it determines whether to adjust selection or not. As you can see, it will always return false. This is why, once you open a node, you will see this odd selection behavior.

While on the topic of tree tables, I recommend that you check out NetBeans' Outline. It is an easy to use implementation, much less convoluted than the JTreeTable example from Sun. You can find links and a demo in this post.

akf
That worked for me. And thanks for the point to the NetBeans Outline.
clartaq
Thank you! I was reluctant to try the netbeans Outline at first, having a bad experience from JXTreeTable, with its crazy static invisible classes preventing you from changing the behavior of the component in a normal way, but the NetBeans thing seems great really! I have now added it to my Eclipse project!
Ed Taylor