Re: JTree display update issue with new nodes



qu0ll wrote:
Thanks Dan. Please see my recent reply to Bart about this. You are absolutely spot on.


Hi qu0ll,

(1) Your code does this and a blank node is displayed (no userObject is specified):
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode();

(2) The DefaultTreeCellRenderer does this:
String stringValue = tree.convertValueToText(value, sel,
expanded, leaf, row, hasFocus);
setText(stringValue);

(3) And the JTree's convertValueToText does this:
if(value != null) {
String sValue = value.toString();
if (sValue != null) {
return sValue;
}
}
return "";

(4) And the DefaultMutableTreeNode is the value and has no userObject so null is returned in it's toString like this:
if (userObject == null) {
return null;
} else {
return userObject.toString();
}

Cheers,

Dan Andrews
- - - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited http://www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - - -
.



Relevant Pages

  • building DefaultTreeModel from List
    ... for (String str: myGroups) ... DefaultMutableTreeNode current = ... MutableTreeNode child, MutableTreeNode parent) ... MutableTreeNode child, MutableTreeNode par, int i) ...
    (comp.lang.java.gui)
  • Re: building DefaultTreeModel from List
    ... DefaultMutableTreeNode node, ... Listlst, int count) ... String grpString = lst.get.getLabel; ... String label; ...
    (comp.lang.java.gui)
  • Re: building DefaultTreeModel from List
    ... DefaultMutableTreeNode node, ... Listlst, int count) ... String grpString = lst.get.getLabel; ... for (String str: myGroups) ...
    (comp.lang.java.gui)
  • Re: custom JTree icons
    ... I looked at their BookInfo class and they don't override the setUserObjectmethod to make it store anything other than a String so how can they get the string to cast to a BookInfo instance and I can't get my string to cast to a Node instance? ... In fact their BookInfo class doesn't even extend the DefaultMutableTreeNode class so how can they even make the ... No need to extend, let alone override, setUserObject. ...
    (comp.lang.java.programmer)
  • Re: Update eines Baumknoten
    ... Ich habe eine Klasse, die DefaultMutableTreeNode erweitert. ... Jedem Knoten wird ein UserObject zugewiesen. ... warum er auf einmal nicht mehr auf das UserObject ...
    (de.comp.lang.java)