wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTreeTable Expansion problems" Watch "JTreeTable Expansion problems" New topic
Author

JTreeTable Expansion problems

Clemens Stich
Greenhorn

Joined: Dec 28, 2005
Posts: 5
Hi,
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: http://www.coderanch.com/t/338967/GUI/java/JTreeTable-tree-DefaultMutableTreeNodes
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
Thanks...
[ January 05, 2006: Message edited by: Clemens Stich ]
A Alex
Greenhorn

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

thanks
A Alex
Clemens Stich
Greenhorn

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
Greenhorn

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

regards
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(),
e.isPopupTrigger());
m_table.getTree().dispatchEvent(newME);
}
m_table.addMouseListener(ml);
 
 
subject: JTreeTable Expansion problems