Re: JTree display update issue with new nodes



"Bart Cremers" <bcremers@xxxxxxxxx> wrote in message
news:1159363228.118727.170500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

qu0ll wrote:
I have a problem with the following code. The code is supposed to create
a
new node and add it as a child to another node in a JTree. This is
indeed
happening but the tree is only updating the display and selecting the new
node the first time a node is added. For each subsequent child node, it
appears as though the child node is added successfully but it is just not
appearing in the tree. If I check getChildCount() on the parent node
after
each child is added it reveals the correct number so it seems to be a
display issue. Could someone please point out the mistake in the
following
code?

This code exists in a control class (not in the JTree itself). The
variable
parentNode is a DefaultMutableTreeNode passed in as a parameter:

<snip>
And loving it,

qu0ll

The problem lies in the fact that you're not correctly implemting
TreeModel functionality (listener notification to be specific in this
case). You're several methods of the DefaultTreeModel in your subclass.
Simply don't override these methods and let the DefaultTreeModel handle
this stuff (nodesWereInserted) and it will work.

You even don't need to use a custom tree model for the functionality
you're using right now. Simply replace it with a DefaultTreeModel and
it'll work.

OK, thanks for that. I replaced my custom tree model with the default and
it works - mostly! Now the new nodes show up but for some reason there is a
blank "line" displayed in the tree like this:

Root
|
* Node
| |
| * Node
| |
| * Node
| <blank space>
* Node
|
* Node

Why the blank space? How do I get rid of it?

--
And loving it,

qu0ll
______________________________________________
qu0llSixFour@xxxxxxxxx
(Replace the "SixFour" with numbers to email)


.



Relevant Pages

  • Re: JTree display update issue with new nodes
    ... new node and add it as a child to another node in a JTree. ... appearing in the tree. ... public class MyTreeModel extends DefaultTreeModel ...
    (comp.lang.java.gui)
  • Re: JTree display update issue with new nodes
    ... new node and add it as a child to another node in a JTree. ... appearing in the tree. ... public class MyTreeModel extends DefaultTreeModel ...
    (comp.lang.java.gui)
  • Re: JTree display update issue with new nodes
    ... new node and add it as a child to another node in a JTree. ... appearing in the tree. ... This code exists in a control class (not in the JTree itself). ... You're several methods of the DefaultTreeModel in your subclass. ...
    (comp.lang.java.gui)
  • Re: How to populate a treeview from a dataset
    ... If it is then check to see if the parentId and child id of the ... 15 is a parent and a child of itself. ... And that same business is the headquarters for the purchasing group. ... 15 Null - root tree node, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to populate a treeview from a dataset
    ... If it is then check to see if the parentId and child id of the ... 15 is a parent and a child of itself. ... And that same business is the headquarters for the purchasing group. ... 15 Null - root tree node, ...
    (microsoft.public.dotnet.languages.csharp)