Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Jtree and TreeNode interface

807591Apr 27 2008 — edited May 2 2008
Hi,

I am trying to create a custom node (a node with a jlabel and a textfield) for a a JTree. I am not entirely sure how to accomplish this, so I a certain route. I tried to create a custom class that extends JLabel and implements TreeNode. Is this the way to do it? If it is, I can't compile because of override error. Look at the code:
public class Node extends JLabel implements TreeNode {
		
		private JLabel label;
		
		public Node () {
			label = new JLabel("TESTST");
		}
		
		public Enumeration children() { return null; }
		
		public boolean isLeaf() { return true; }
		
		public boolean getAllowsChildren() { return true; }
		
		public int getIndex(TreeNode node) { return 0; }
		
		public TreeNode getParent() { return null; }
		
		public int getChildCount() { return 0; }
		
		public TreeNode getChildAt(int childIndex) { return null; }
}
The problem is the getParent() method. This method is defined in java.awt.Component, and I can thus not override it because there is an incompatible returntype. Is there a way around this? Creating a custom tree is confusing.

Edited by: Siniz on Apr 27, 2008 4:47 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 30 2008
Added on Apr 27 2008
8 comments
269 views