Hi, I'm working with a Jtree and pulling data from a DB, essentially I was doing this
Which was good, but I got a problem since my toString() method on Object returns the PK of my entity, not the name, as names are not unique.... and I really need it to be the whole Object and not just the name attribute for later acces to its childrens
So I'm thinking of
Keep in mind those codes go inside a for loop.
Last idea doesn't seem right, as I'm creating a whole map for each registry, is there a proper way to achieve what I need?
If I got it right, you are creating a map only for calling its toString()?
If you want to change the node text without changing the toString() of your Folder objects then you can use convertValueToText() method in JTree.
Joined: Aug 11, 2009
I kinda don't get how to use it.
What I have here is a JTree which Nodes are Folder Objects, and I need them to stay as Folder or contain a Folder
By just placing Folder inside the node it calls its toString whenever it renders a Node on JTree, so the text shows like pk=100
What I did for now is instead of using the Map, made a class called Pair which toString() returns the .getName of the Object, so I just do something like
That shows the text and lets me retrieve the Folder object later. How you do it with convertValueToText?
The default models that are found in Java are created in an generic way. The DefaultMutableTreeNode takes any kind of Object and wraps around it. If you want to use something else than the .toString, you should create yourself a FolderTreeNode or a small FolderWrapper that goes into the DefaultMutableTreeNode.
Pablo Mino wrote:How you do it with convertValueToText?
Whenever JTree renders a node, it gets the display text using convertValueToText method.
Default Implementation of convertValueToText() in JTree just returns value.toString(); which in turn calls userObject.toString(); which in your case is the toString() method of your Folder object.
Its pretty easy to customize the rendering. You just have to override this method in your JTree. For Example:
Joined: Aug 11, 2009
I get it now, thanks
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com