• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add a JLabel in any leaf of a JTree

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add a JLabel in any Leaf of a JTree . I tried to use TreeCellRenderer but I don't know how to implement it properly.
Following is a sample code where I want to add a JLabel in the leaf of a JTree but I am not getting proper output.

 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why a JLabel? Just use a String, it gets rendered as a JLabel by default anyway.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLabel because actually my application wants JTextPane , Combo Boxes and all . So atleast any of these implementation will show me the way to use other components.

So , please show the way to use it.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> So , please show the way to use it.

did you try the tutorial?

http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I tried the url as well but an example for my code will show me a proper way to start.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buntha Choudhary wrote:Yes I tried the url as well but an example for my code will show me a proper way to start.

You mean you didn't scroll down the page enough to see that there are code samples in the tutorial? Really!
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried and I code as well . I just could not found some scenarios very clear like I added a JButton but how put action to that button. Similarly with JTextField and all other components.

If any link is there where sample codes are there , please provide me.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> If any link is there where sample codes are there , please provide me.

there's plenty in the link
there's plenty on this site
there's plenty at google

if you really can't get started, pay someone, or change careers
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried but I am not able to add the action event to the JButton in the JTree . According to the example given , Under ROOT , there are 4 Menus and under Menu3 , there is a submenu as JButton , but action events are not working.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luckily I saw your cross-post before I posted a solution

http://forums.sun.com/thread.jspa?threadID=5435113&tstart=0

bye.
 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted in other forums as well because I am really not sure about the solution of my problem .
I did not know that these forums are related and my post will be considered as a cross post.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be Forthright When Cross Posting To Other Sites.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic