Solved

Node text changes when I edit it - how to stop this?

Posted on 2013-11-01
1
210 Views
Last Modified: 2013-11-17
I create a treenode as follows...

DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("mytext,GroupIcon");

Open in new window


Then I use a custom renderer to parse the data to determine what icon to use...
case "GroupIcon":
				this.setIcon(new ImageIcon(frmMyForm.class.getResource("/proj6/java/group.png")));
				setText(x[0]);
				break;

Open in new window



The node shows text "mytext" as it should and the icon is correct.  The only problem is when you edit the node (by double-clicking on it), the text changes to the full value of "mytext,GroupIcon".  How can I fix this?

Simply changing the icon using another method is not the answer I'm looking for because of other factors.

I tried creating custom node with custom properties like this...

n1.setStrIconType = "Group";

Open in new window


but I couldn't seem to access the custom properties within the custom renderer.

Any help would be appreciated.
0
Comment
Question by:pdering
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
Comment Utility
If you want to do it that way you would have to provide similar logic as in the Renderer, in a custom TreeCellEditor aswell. With what you have posted, that's about as much as I can say. If you need more help than that, can you post your full code?

Also, I think the way that you were going with using a custom TreeNode class is probably the best. If you can post what you did there, we can probably help overcome the difficulty that you had accessing the custom properties.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now