Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTreeTable Selection

 
Dhivya Krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.,
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...,

Can someone please help with the above issue..
 
Veena Nair
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(),
me.isPopupTrigger());
tree.dispatchEvent(newME);
break;
}
}
}
return false;
}
 
Dhivya Krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic