DefaultTreeNode exception when being modified from a different thread

Hi,

I have two panels, each one displays a separate tree structure, when I attempt to copy from one tree to another in a different thread I get the following exception.

Exception in thread"AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 84 >= 83

at java.util.Vector.elementAt(Vector.java:427)

at javax.swing.tree.VariableHeightLayoutCache.getNode(VariableHeightLayoutCache.java:976)

at javax.swing.tree.VariableHeightLayoutCache.getPreferredHeight(VariableHeightLayoutCache.java:274)

at javax.swing.plaf.basic.BasicTreeUI.updateCachedPreferredSize(BasicTreeUI.java:1872)

at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize(BasicTreeUI.java:2015)

at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize(BasicTreeUI.java:2003)

at javax.swing.JComponent.getPreferredSize(JComponent.java:1627)

at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)

at java.awt.Container.layout(Container.java:1432)

at java.awt.Container.doLayout(Container.java:1421)

at java.awt.Container.validateTree(Container.java:1519)

at java.awt.Container.validate(Container.java:1491)

at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:639)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Obviously if I revert back the copying to the same thread the problem is avoided, however the program appears to be frozen for the duration of the copying. I also tried changing the way that the information is displayed (ie in a table) and that did not throw exceptions.

I also found this http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4704869 on the Sun Website, however there was no solution.

Therefore, how do I construct a tree that can be modified from a separate thread.

Any assistance greatly appreciated.

[2587 byte] By [lnem2a] at [2007-11-27 5:59:18]
# 1

The bug you referred to states that the exception is due to the tree being modified by a thread not being the EDT.

What kind of thread are you using? The 玞orrect?way of doing this would be by using SwingWorker: http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html

If you were not, please give SwingWorer a try and tell us if the exception is still thrown!

rebola at 2007-7-12 16:35:39 > top of Java-index,Desktop,Core GUI APIs...