Related to the first of your questions, you should implement a TreeCellRenderer.
Guessing that you do would do something similar to:
//and override also all the other functions of TreeCellRenderer
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
Component returnValue = null;
if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
Object userObject = ((DefaultMutableTreeNode) value)
.getUserObject();
if (userObject instanceof YourClass) {
YourClass yourElement = (YourClass) userObject;
if(col==0) titleLabel.setText(yourElement.getID());
if(col==1) titleLabel.setText(yourElement.getName());
if(col==2) titleLabel.setText(yourElement.getParentID());
if (selected) {
renderer.setBackground(backgroundSelectionColor);
} else {
renderer.setBackground(backgroundNonSelectionColor);
}
renderer.setEnabled(tree.isEnabled());
returnValue = renderer;
}
}
if (returnValue == null) {
returnValue = defaultRenderer.getTreeCellRendererComponent(tree,
value, selected, expanded, leaf, row, hasFocus);
}
return returnValue;
}
}
What is currently happening to you is that your Cell Renderer is returning the Object instance element ID (DictionaryItem@11abb71 for example) instead of getting the object and call the getID() function.
You can find extra example and information on TreeCellRenderer example.
Related to your second question see the example on TreeModel example. Maybe you can also try to expand the row by code.
If the "+" icon is changing to a "-" it would probably means that getChildCount is working well but what it isn't working is the getChild(int row) which will return null or an unvalid tree row element.