• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Multiline JLabel  RSS feed

 
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 ?
 
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.
 
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.

----
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use a JTextArea, setEditable(false).
 
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
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
Boost this thread!