It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes JTreeTable Selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTreeTable Selection" Watch "JTreeTable Selection" New topic

JTreeTable Selection

Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 68
My jtreetable is working fine but with this issue.
1) After expanding the node from the tree., the sub node gets selected only if i click in first column. I want to know if this is the feature of treetable that click on first column icon alone selects the row.
2) On Collapse, the treetable doesn't get refreshed., though it closes the node the selected row is still visible.
Please let me know more about this jtreetable if someone has worked on it.
Thanks in Advance.
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 68

Can someone please help with the above issue..
Veena Nair

Joined: Jul 08, 2012
Posts: 13
Hi Divya..
It would have been better if you have added the code which you used so that others can easily make out the issue.. I think the selection properties can be changed according to programmer's wish..
Just go through the following link ... that might solve your problem..! webpage
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

There are a few JTreeTable implementations out there - so, you need to let us know which one you are using. Most people use the 'original' JTreeTable - an article written on Sun in 2000 or so.
There is also the SwingX JTreeTable and Netbeans Outline (ETable)...

Specifically, make sure your implementation of getChild(), getChildCount() and getIndexOfChild() methods of TreeTableModel is correct.

Try to create a simple example and post the sscce.

Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 68
I found the solution for this problem. Override the IsCellEditable method of your treetablecelleditor. Below is the code.

* Overridden to return false, and if the event is a mouse event
* it is forwarded to the tree.<p>
* The behavior for this is debatable, and should really be offered
* as a property. By returning false, all keyboard actions are
* implemented in terms of the table. By returning true, the
* tree would get a chance to do something with the keyboard
* events. For the most part this is ok. But for certain keys,
* such as left/right, the tree will expand/collapse where as
* the table focus should really move to a different column. Page
* up/down should also be implemented in terms of the table.
* By returning false this also has the added benefit that clicking
* outside of the bounds of the tree node, but still in the tree
* column will select the row, whereas if this returned true
* that wouldn't be the case.
* <p>By returning false we are also enforcing the policy that
* the tree will never be editable (at least by a key sequence).
public boolean isCellEditable(EventObject e) {
if (e instanceof MouseEvent) {
for (int counter = getColumnCount() - 1; counter >= 0;
counter--) {
if (getColumnClass(counter) == TreeTableModel.class) {
MouseEvent me = (MouseEvent)e;
MouseEvent newME = new MouseEvent(tree, me.getID(),
me.getWhen(), me.getModifiers(),
me.getX() - getCellRect(0, counter, true).x,
me.getY(), me.getClickCount(),
return false;
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 68
My other issue now is., Muliple row selection in a JTreeTable is not working.Multiple selection works on below conditions
1. Pressing the Shift button and moving the mouse down selects multiple rows.
2. Selecting one row and moving the down or up arrow selects multiple rows.

But on pressing control key and trying to select specific rows doesn't work.

Can someone help me out in this.
I agree. Here's the link:
subject: JTreeTable Selection
It's not a secret anymore!