aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Multiline JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Multiline JLabel" Watch "Multiline JLabel" New topic
Author

Multiline JLabel

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
Hi All,
How can i have two lines in the JLabel ?
Shan Accent
Greenhorn

Joined: May 08, 2005
Posts: 23
Haim

You can override the paintComponent(Graphics g) method and draw a line.
satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
I mean how can i have multi line text in a JLable ??

Exa : Enter name or
Enter nickname
This 2 line text will be in one JLable.
Matthew Taylor
Rancher

Joined: Jun 13, 2004
Posts: 110


Grails Consultant
http://dangertree.net
Shan Accent
Greenhorn

Joined: May 08, 2005
Posts: 23
Peter Glass code exactly correct. - it's one way.

other way is .
In JLable or JPanel it self add What ever component you want with needed layout.

----
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Or use a JTextArea, setEditable(false).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Tom McC
Greenhorn

Joined: Jul 28, 2005
Posts: 21
If you're using Ilja's idea, I usually use this code to make the JTextArea seem as much like a JLabel as possible:

and if you want it to use word wrapping:

[ August 24, 2005: Message edited by: Tom McC ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Thanks - I didn't know about setCursor and setFocusable!

I'd also add



We even have some code that calculates the preferredSize (and encapsulated all that in an AutoWrappingLabel class).
 
Don't get me started about those stupid light bulbs.
 
subject: Multiline JLabel