Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTree

0 views
Skip to first unread message

Thierry Hanot

unread,
Feb 2, 2001, 1:10:23 PM2/2/01
to

Hello
Is somebody know how to synchronize a DefaultTreeModel and its display
???
I have a dynamic tree which is modify by some threads.
When i do some model.insertNodeInto and some
model.removeNodeFromParent in those thread , during the redraw i have
the following exception ( not all the time ).

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
at java.util.Vector.elementAt(Vector.java:417)
at
javax.swing.tree.DefaultMutableTreeNode.getChildAt(DefaultMutableTreeNode.java:231)

at
javax.swing.tree.DefaultTreeModel.getChild(DefaultTreeModel.java:151)
at
javax.swing.tree.FixedHeightLayoutCache$VisibleFHTreeStateNodeEnumeration.nextElement(FixedHeightLayoutCache.java:1485)

at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1070)
at javax.swing.plaf.metal.MetalTreeUI.paint(MetalTreeUI.java:139)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:39)
at javax.swing.JComponent.paintComponent(JComponent.java:398)
at javax.swing.JComponent.paint(JComponent.java:739)
at javax.swing.JComponent.paintChildren(JComponent.java:523)
at javax.swing.JComponent.paint(JComponent.java:748)
at javax.swing.JViewport.paint(JViewport.java:668)
at javax.swing.JComponent.paintWithBuffer(JComponent.java:4393)
at javax.swing.JComponent._paintImmediately(JComponent.java:4336)
at javax.swing.JComponent.paintImmediately(JComponent.java:4187)
at
javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:370)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:205)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:331)
at
java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)\


Even if i synchronize access to the treemodel i still have the ....
exception sometime

while (iter.hasNext()) {
JobUnitImpl ju = (JobUnitImpl) iter.next();
JobUnitNode jun = new JobUnitNode(ju, model, JOB_DATA);
//////////////////////////////////////////////////
synchronized (model) {
model.insertNodeInto(jun, this, 0);
}
/////////////////////////////////////////////////
jun.buildChildren();
}

Is somebody can help me


Thanks

ps: sorry for my english , i 'm a poor little frenchy a bit exasperate
by this problem

Christian Kaufhold

unread,
Feb 2, 2001, 1:50:19 PM2/2/01
to
Thierry Hanot <thierr...@ms.alcatel.fr> wrote:


> Hello
> Is somebody know how to synchronize a DefaultTreeModel and its display
> ???
> I have a dynamic tree which is modify by some threads.


You cannot do that. As Swing's model-inspecting code does not synchro-
nize on the model while inspecting, there is no change to lock it during
modifying, thus assumptions that the code makes (for example that no chil-
dren are added or removed during execution) fail.
You have to perform the actual change in the event-dispatch thread,
using SwingUtitities.invokeLater, for example.

Christian
--
"But 'glory' doesn't mean 'a nice knock-down argument,'" Alice objected.
"When I use a word," Humpty Dumpty said in rather a scornful tone, "it
means just what I choose it to mean -- neither more nor less."
Through the Looking-Glass

Bruno

unread,
Feb 4, 2001, 6:01:55 PM2/4/01
to
How can edit selected tree node without mouse.
I have JPopupMenu and with option "RENAME" I want rename
selected node in the tree.

Thanks,
Bruno


Bruno

unread,
Feb 4, 2001, 6:00:41 PM2/4/01
to

Babu Kalakrishnan

unread,
Feb 5, 2001, 12:22:18 AM2/5/01
to
On Mon, 5 Feb 2001 00:00:41 +0100, Bruno <ti...@ck.tel.hr> wrote:
>How can edit selected tree node without mouse.
>I have JPopupMenu and with option "RENAME" I want rename
>selected node in the tree.

I suppose you mean start the editing programmatically ?

Have you tried tree.startEditingAtPath(path) ?

Kala


0 new messages