Skip to main content

JTreeTable expand/collapse problem

5 replies [Last post]
edeandrea
Offline
Joined: 2004-11-22

I am relatively new to the JDNC. I am trying to use the JTreeTable classes. I have my own TreeTableModel class, which I extended from AbstractTreeTableModel. When I cal setTreeTableModel on my JTreeTable, I see the correct data, but there is no way to expand/collapse the nodes. There are also no icons there to show that a node can be expanded or collapsed (like the little + and - icons you would see in Windows Explorer). Is there something else that I have to do? My TreeTableModel always returns true in the isCellEditable method.

Also I'm seeing some other weird behavior...Whenever I move my mouse over a cell, I'm getting tons of exceptions that look like this:

Exception occurred during event dispatching:
java.lang.ClassCastException
at org.jdesktop.swing.JXTable.getColumnExt(JXTable.java:480)
at org.jdesktop.swing.LinkHandler.isLinkColumn(LinkHandler.java:54)
at org.jdesktop.swing.LinkHandler.setCursor(LinkHandler.java:63)
at org.jdesktop.swing.LinkHandler.mouseMoved(LinkHandler.java:48)
at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:272)
at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:271)
at java.awt.Component.processMouseMotionEvent(Component.java:5145)
at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:2779)
at java.awt.Component.processEvent(Component.java:4901)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3211)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:141)
at java.awt.Dialog$1.run(Dialog.java:540)
at java.awt.Dialog.show(Dialog.java:561)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at com.putnaminv.pc.client.dialog.BaseDialog.setVisible(BaseDialog.java:130)
at com.putnaminv.pc.client.dialog.portfolioProperties.AccountPropertiesPanel.showTrustInfoBtn_actionPerformed(AccountPropertiesPanel.java:319)
at com.putnaminv.pc.client.dialog.portfolioProperties.AccountPropertiesPanel.access$100(AccountPropertiesPanel.java:45)
at com.putnaminv.pc.client.dialog.portfolioProperties.AccountPropertiesPanel$2.actionPerformed(AccountPropertiesPanel.java:205)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:141)
at java.awt.Dialog$1.run(Dialog.java:540)
at java.awt.Dialog.show(Dialog.java:561)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at com.putnaminv.pc.client.dialog.portfolioProperties.PortfolioPropertiesDialog.setVisible(PortfolioPropertiesDialog.java:276)
at com.putnaminv.pc.client.dialog.openEditProduct.OpenSelectProductDialog.propButton_actionPerformed(OpenSelectProductDialog.java:418)
at com.putnaminv.pc.client.dialog.openEditProduct.OpenSelectProductDialog$6.actionPerformed(OpenSelectProductDialog.java:278)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:141)
at java.awt.Dialog$1.run(Dialog.java:540)
at java.awt.Dialog.show(Dialog.java:561)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at com.putnaminv.pc.client.dialog.openEditProduct.OpenSelectProductDialog.setVisible(OpenSelectProductDialog.java:336)
at com.putnaminv.pc.client.app.AppController.selectCurrentPortfolio(AppController.java:1478)
at com.putnaminv.pc.client.menu.PCFileMenu$openProductListener.actionPerformed(PCFileMenu.java:240)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tiom
Offline
Joined: 2003-09-24

You should override
[code]
public Class getColumnClass(int column);
return column == 0 ? TreeTableModel.class : super.getColumnClass();
[/code]

That should do it.

edeandrea
Offline
Joined: 2004-11-22

That didn't do it...No change in what I see...

bino_george
Offline
Joined: 2003-06-16

Hi,
What does your nodes do ? Do they implement
getChildren, isLeaf, getAllowsChildren etc ?
The expand/collapse will only show if the nodes
are non-leaf.

If you send me a simple testcase with your model and
Node implementation, I could see what is wrong.

Thanks,
Bino.

edeandrea
Offline
Joined: 2004-11-22

Hi Bino,
Maybe I just don't understand how it is all supposed to work, so please correct me if I am wrong. I was under the assumption that all you had to do was create a TreeTableModel around your objects and then magically your tree would render appropriately, similar to how a table works. I'm very familiar with creating TableModels from extending AbstractTableModel, so I was assuming that TreeTables worked the same way. All of the method signatures in TreeTableModel (getParent, getChild, getRoot, getValueAt, etc) have the return type of Object, so what I am returning the correct object in my object structure in each of these methods. Again I may have the wrong perception of how this is supposed to work, so please correct me if I'm wrong. Thanks!

bino_george
Offline
Joined: 2003-06-16

Hi,
A tree is quite different from the Table since it
supports children and the nodes have a recursive nature
to it. So basically to do anything useful you will also
have to subclass TreeNode or DefaultMutableTreeNode if
it is mutable. The TreeTable is a kind of tree where the
leaf nodes can have multiple columns.

Take a look at the tree tutorial to understand how to
work with trees :

http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Thanks,
Bino.