Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes How to add a JLabel in any leaf of a JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add a JLabel in any leaf of a JTree" Watch "How to add a JLabel in any leaf of a JTree" New topic
Author

How to add a JLabel in any leaf of a JTree

buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Why a JLabel? Just use a String, it gets rendered as a JLabel by default anyway.
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Jul 03, 2009
Posts: 136

Yes I tried the url as well but an example for my code will show me a proper way to start.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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!


luck, db
There are no new questions, but there may be new answers.
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Jul 03, 2009
Posts: 136

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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Jul 03, 2009
Posts: 136

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

Joined: Oct 27, 2005
Posts: 19655
    
  18

Be Forthright When Cross Posting To Other Sites.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add a JLabel in any leaf of a JTree
 
Similar Threads
JTree
Code for JTree with checkbox
Checkbox with Jtree
JTable In JTree
How to checked CheckBox in JTree only when user click on CheckBox?