Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a multiple line JLabel.  RSS feed

 
Garandi Garandi
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
 
Matt Wilcko
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");
 
kyle amburn
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
 
VIJAY Yadlapati
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.
 
Tamizh Selvan
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!