• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiline JLabel

 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
How can i have two lines in the JLabel ?
 
Shan Accent
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haim

You can override the paintComponent(Graphics g) method and draw a line.
 
satya sahu
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Shan Accent
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use a JTextArea, setEditable(false).
 
Tom McC
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic