• 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

How to create a multiple line JLabel.  RSS feed

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have a JLabel with multiple lines, I try to use html tages, but the tages are visible on the Label.
Q1: How to create a multiple line JLabel.
This is what I did and it did not work.

<html> and <br> tages are visible on the label.
Thank you inadvance
Garandi
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using a new line escape character? \n
Try this:
JLabel label = new JLabel("This is line one\nThis is line two");
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That same method works for me. What version sdk are you using? HTML support is only added from 1.2.2 on.
Kyle
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply, but for some reason it works for me now too.
Thank you
Garandi
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use
JLabel label = new JLabel("<html>This is line one<br>THis is line two </html>"); for single break between the lines.
Try this in HTML, and see the difference.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can also try using JTextArea . with setting setEditable(false).
hope this w'd help u.
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using a textarea, you should have to set empty border for it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!