Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3968 > unrolled thread

JTree - subnode not added

Started by"pelakh" <pelakh@THRWHITE.remove-dii-this>
First post2011-04-27 15:47 +0000
Last post2011-04-27 15:48 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  JTree - subnode not added "pelakh" <pelakh@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
    Re: JTree - subnode not a "Daniele Futtorovic" <daniele.futtorovic@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
      Re: JTree - subnode not a "John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
        Re: JTree - subnode not a "pelakh" <pelakh@THRWHITE.remove-dii-this> - 2011-04-27 15:48 +0000

#3968 — JTree - subnode not added

From"pelakh" <pelakh@THRWHITE.remove-dii-this>
Date2011-04-27 15:47 +0000
SubjectJTree - subnode not added
Message-ID<c041d8e8-cab7-4e4b-a247-4eb165e62237@m3g2000hsc.googlegroups.com>
  To: comp.lang.java.gui
I have a simple JTree in one of my panels, using the DefaultTreeModel
populated with
my own FileTreeNode objects, which extend DefaultMutableTreeNodes. I
am adding
nodes into the tree by doing parentNode.add(subNode), which seems to
work just
fine in most cases. However, in a particular case, my new nodes don't
show up, even
though I can find them both in the children of the parent and through
the tree model.
Right after the add, I call repaint to update the tree, and then trace
some debug information
I get the following:

*** This is the first insertion - it works fine ***
Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 1]
is 22 bounds are java.awt.Rectangle[x=80,y=420,width=82,height=20]

*** This is the same trace for any consequent insertion - does not
work***
Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 2]
is -1 bounds are null

It is as if the TreeUI completely loses this node. Furthermore, the
vertical line preceding the
label of 'Baseline 1' disappears after 'Baseline 2' is added, but that
is the only visible side
effect.

So, where has my missing node(s) gone?

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#3969 — Re: JTree - subnode not a

From"Daniele Futtorovic" <daniele.futtorovic@THRWHITE.remove-dii-this>
Date2011-04-27 15:47 +0000
SubjectRe: JTree - subnode not a
Message-ID<g7to9c$m5q$1@registered.motzarella.org>
In reply to#3968
  To: comp.lang.java.gui
On 13/08/2008 05:43, pelakh@yahoo.com allegedly wrote:
> I have a simple JTree in one of my panels, using the DefaultTreeModel
> populated with
> my own FileTreeNode objects, which extend DefaultMutableTreeNodes. I
> am adding
> nodes into the tree by doing parentNode.add(subNode), which seems to
> work just
> fine in most cases. However, in a particular case, my new nodes don't
> show up, even
> though I can find them both in the children of the parent and through
> the tree model.
> Right after the add, I call repaint to update the tree, and then trace
> some debug information
> I get the following:
> 
> *** This is the first insertion - it works fine ***
> Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
> Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 1]
> is 22 bounds are java.awt.Rectangle[x=80,y=420,width=82,height=20]
> 
> *** This is the same trace for any consequent insertion - does not
> work***
> Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
> Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 2]
> is -1 bounds are null
> 
> It is as if the TreeUI completely loses this node. Furthermore, the
> vertical line preceding the
> label of 'Baseline 1' disappears after 'Baseline 2' is added, but that
> is the only visible side
> effect.
> 
> So, where has my missing node(s) gone?

Do you perform the node addition on the event dispatch thread (EDT)? You 
ought to.

-- 
DF.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#3970 — Re: JTree - subnode not a

From"John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this>
Date2011-04-27 15:47 +0000
SubjectRe: JTree - subnode not a
Message-ID<nospam-87B10E.01291813082008@aioe.org>
In reply to#3969
  To: comp.lang.java.gui
In article <g7to9c$m5q$1@registered.motzarella.org>,
 Daniele Futtorovic <da.futt.news@laposte.invalid> wrote:

> On 13/08/2008 05:43, pelakh@yahoo.com allegedly wrote:
> > I have a simple JTree in one of my panels, using the 
> > DefaultTreeModel populated with my own FileTreeNode objects, which 
> > extend DefaultMutableTreeNodes. I am adding nodes into the tree by 
> > doing parentNode.add(subNode), which seems to work just fine in 
> > most cases. However, in a particular case, my new nodes don't show 
> > up, even though I can find them both in the children of the parent 
> > and through the tree model. Right after the add, I call repaint to 
> > update the tree, and then trace some debug information I get the 
> > following:
> > 
> > *** This is the first insertion - it works fine ***
> > Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
> > Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 1]
> > is 22 bounds are java.awt.Rectangle[x=80,y=420,width=82,height=20]
> > 
> > *** This is [...] any consequent insertion - does not work***
> > Row for freq [TreeRoot, Smooth Files, AC #377, 20.250] is 21
> > Row for new path [TreeRoot, Smooth Files, AC #377, 20.250, Baseline 2]
> > is -1 bounds are null
> > 
> > It is as if the TreeUI completely loses this node. Furthermore, the 
> > vertical line preceding the label of 'Baseline 1' disappears after 
> > 'Baseline 2' is added, but that is the only visible side effect.
> > 
> > So, where has my missing node(s) gone?
> 
> Do you perform the node addition on the event dispatch thread (EDT)? 
> You ought to.

pelakh: Daniele is right. I was looking at the tutorial, and the demos 
do precisely that in via invokeLater():

<http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html>
<http://java.sun.com/docs/books/tutorial/uiswing/examples/zipfiles/compon
ents-TreeDemoProject.zip>

Looking closer, I see DefaultMutableTreeNode is not thread safe:
 
<http://java.sun.com/javase/6/docs/api/javax/swing/tree/DefaultMutableTre
eNode.html>

-- 
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#3975 — Re: JTree - subnode not a

From"pelakh" <pelakh@THRWHITE.remove-dii-this>
Date2011-04-27 15:48 +0000
SubjectRe: JTree - subnode not a
Message-ID<52e91f8e-f405-4781-8347-824924d07b29@d77g2000hsb.googlegroups.com>
In reply to#3970
  To: comp.lang.java.gui
Well, the EDT was not it, but looking through the example code you
sent me, I was able to find my solution - instead of adding directly
to the node, I used the DefaultTreeModel.insertNodeInto() method,
which generated the proper NodesInserted events to keep the tree
consistent.

Thanks!

On Aug 13, 1:29=A0am, "John B. Matthews" <nos...@nospam.invalid> wrote:
> pelakh: Daniele is right. I was looking at the tutorial, and the demos
> do precisely that in via invokeLater():
>
> <http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html>
> <http://java.sun.com/docs/books/tutorial/uiswing/examples/zipfiles/compon=
ents-TreeDemoProject.zip>
>
> Looking closer, I see DefaultMutableTreeNode is not thread safe:
>
> <http://java.sun.com/javase/6/docs/api/javax/swing/tree/DefaultMutableTre=
eNode.html>
>
> --
> John B. Matthews
> trashgod at gmail dot com
> home dot woh dot rr dot com slash jbmatthews

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web