This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTreeTable Expansion problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTreeTable Expansion problems" Watch "JTreeTable Expansion problems" New topic

JTreeTable Expansion problems

Clemens Stich

Joined: Dec 28, 2005
Posts: 5
I tried to customize the JTreeTable from the sun homepage. My tree consists out of DefaultMutableTreeNodes (to be more exactly, an extension of DefaultMutableTreeNodes).
My goal is to get a working TreeTable that has a tree in the first column and according to this tree checkboxes in the second column.
I searched the forum and found this thread:
It helped me a lot and I did the things as mentioned in this thread. My problem is now, that I cannot expand the tree and I don't know why...

The code in my TreeTableModel impl class looks like that:

And I create the JTreeTable like this:

For explanation: MyTreeNode's userobject can either be a normal String or an Object of type of MyOwnClass (as you see above). The nodes which represents just a String are always the parent, and the nodes which represents MyOwnClass are always the children (= leafs). I of course overwrote some methods in MyTreeNode. I know that the implementation of MyTreeNode is correct, because I used it before in a normal tree and there it worked.

I am really hoping that someone can help me
[ January 05, 2006: Message edited by: Clemens Stich ]
A Alex

Joined: Jan 24, 2006
Posts: 2
Could you figure out the problem with the treetable , Since I am having teh same problem , please let me know if you find any

A Alex
Clemens Stich

Joined: Dec 28, 2005
Posts: 5
No I have no idea how to solve that problem.
Because my tree had a simple binary structure, I decided not to use the TreeTable, but I used a simple table and I just simulated a tree-like view in that table. This isn't the nicest thing to do, but it worked and it was relatively simple
A Alex

Joined: Jan 24, 2006
Posts: 2
If you are interested I did find the solution
Just add a mouse listner to the table and dispatch the
mouse events to the tree , I havent seen any issues with this
till now . The code section I used is given below

A Alex

MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int selRow = m_table.getTree().getRowForLocation(e.getX(), e.getY());
TreePath selPath = m_table.getTree().getPathForLocation(e.getX(), e.getY());

if(selRow != -1) {
if(e.getClickCount() == 1) {
// System.out.println("one Selrow ="+selRow+" selpath="+selPath);
} else if(e.getClickCount() == 2) {
// System.out.println("two Selrow ="+selRow+" selpath="+selPath);
MouseEvent newME = new MouseEvent(m_table.getTree(), e.getID(),
e.getWhen(), e.getModifiers(),
e.getX() - m_table.getCellRect(0, 0, true).x,
e.getY(), e.getClickCount(),
I agree. Here's the link:
subject: JTreeTable Expansion problems
It's not a secret anymore!