Gabriel Kecske

Greenhorn
+ Follow
since Jul 11, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gabriel Kecske

Paul, could you please guide me how can i make of use that code, how can i implement it to my jtree? Thank you very much in advance!

BTW I use this to populate the jtree with data:



and im using it like this, where dir is a path:

7 years ago

Paul Clapham wrote:You might find it a lot easier for your DefaultMutableTreeNode to just override toString() to return whatever you want to see in the tree node and you don't need to mess about with cell renderers. Something like this:



You'll probably need a suitable constructor as well but that's the part which answers your question.



Hey Paul :) Thank you for the answer. I tried your solution, and i have one question. How come if FileTreeNode extends DefaultMutableTreeNode it doesnt recognize node object? Or i miss something? it says: "node cannot be resolved"
7 years ago

Rob Spoor wrote:Sure it is. Your renderer just needs to do the correct thing.

Let's start with your model. I assume you have a DefaultTreeModel with DefaultMutableTreeNodes, and those DefaultMutableTreeNodes contain Files. Is this correct? Can you validate this by printing out the values?
You should now be able to see what the values actually are. Perhaps they are not what you want.

What I usually do when creating renderers (TableCellRenderer, ListCellRenderer or TreeCellRenderer) is call super.getXxxRendererComponent at the end, with a possibly other value. For instance:



Hi Rob!

Thank you for the answer yes it does print out the node values as i excepted. I have one more question, is it enough to initialize a custom renderer like:
or I have to do anything else? Because I think this renderer now should work, it should make those changes that i want but it doesnt
7 years ago

Rob Spoor wrote:Try changing value on lines 12-13 into userValue.



Thank you Rob for taking your time to answer me. I tried to change those as you suggested but still not working. I'm starting to wonder if its even possible to show only names not full path :-/
7 years ago
Thank you for the response Darryl. I really dont know how the posted code could be more SSCCE compatible, it has only that code that i have problem with it. I didnt posted the all 1200+ lines. By the way I tried to remove the outer condition , but its still not working.
7 years ago
Hello guys!

I would like to ask your help about JTree custom renderer. I've been trying to figure out what could be wrong with this. Here's the deal:

I have a Jtree which suppose to view the structure of given folder, so far so good its working. But my problem is that i dont want it to show the full path as name, only folder name and file name. I wrote a custom JTree renderer in hope that this will solve my problem but it didnt.

Here is my custom Jtree renderer:



and here is where Im trying to implement it:



I have no idea what could be wrong
7 years ago