Questions tagged [jlabel]

A Java Swing component to display a short text string or an image, or both.

A JLabel object can display either text, an image, or both. You can specify where in the label's display area the label's contents are aligned by setting the vertical and horizontal alignment. By default, labels are vertically centered in their display area. Text-only labels are leading edge aligned, by default; image-only labels are horizontally centered, by default.

Unlike text fields and many other controls, JLabels are transparent by default: parent content is visible in places not covered by text and icon, and setting the background colour has no effect. JLabel can be made opaque by setOpaque(true).

Reference: Class JLabel

3150 questions
156
votes
4 answers

How do I set a JLabel's background color?

In my JPanel, I set the background of a JLabel to a different color. I can see the word "Test" and it's blue, but the background doesn't change at all. How can I get it to show? this.setBackground(Color.white); JLabel label = new…
Catalina Island
  • 6,750
  • 2
  • 21
  • 38
112
votes
6 answers

Newline in JLabel

How can I display a newline in JLabel? For example, if I wanted: Hello World! blahblahblah This is what I have right now: JLabel l = new JLabel("Hello World!\nblahblahblah", SwingConstants.CENTER); This is what is displayed: Hello…
mportiz08
  • 9,516
  • 12
  • 38
  • 42
93
votes
12 answers

How to add hyperlink in JLabel?

What is the best way to add a hyperlink in a JLabel? I can get the view using html tags, but how to open the browser when the user clicks on it?
amit
  • 10,141
  • 10
  • 58
  • 59
84
votes
9 answers

make a JLabel wrap it's text by setting a max width

I have a JLabel which has a lot of text on it. Is there a way to make the JLabel have a max width so that it will wrap the text to make it not exceed this width? Thanks
Aly
  • 14,299
  • 42
  • 109
  • 181
82
votes
11 answers

Multiline text in JLabel

How can I make the text of a JLabel extend onto another line?
Jessy
  • 13,883
  • 31
  • 80
  • 100
77
votes
6 answers

How to change the size of the font of a JLabel to take the maximum size

I have a JLabel in a Container. The defaut size of the font is very small. I would like that the text of the JLabel to take the maximum size. How can I do that?
g123k
  • 3,476
  • 6
  • 38
  • 44
53
votes
7 answers

Is there a "word wrap" property for JLabel?

I am displaying some text in a JLabel. Basically I am generating that text dynamically, and then I apply some HTML tags (e.g., BR and B) to format the text. Finally I assign this formatted text to my JLabel. Now I want my Jlabel to automatically…
Jame
  • 18,248
  • 32
  • 76
  • 102
53
votes
7 answers

Java swing: Multiline labels?

Possible Duplicate: Multiline text in JLabel I want to do this: JLabel myLabel = new JLabel(); myLabel.setText("This is\na multi-line string"); Currently this results in a label that displays This isa multi-line string I want it to do this…
bguiz
  • 22,661
  • 40
  • 140
  • 226
49
votes
3 answers

Align text in JLabel to the right

I have a JPanel with some JLabel added with the add() method of JPanel. I want to align the JLabel to the right like the image below but I don't know how to do that. Any Idea? Thanks!
Luca
  • 1,496
  • 3
  • 26
  • 40
42
votes
3 answers

How to center the text in a JLabel?

despite many tries I can't get the result that I would like to see - text centered within the JLabel and the JLabel somewhat centered in the BorderLayout. I said "somewhat" because there should be also another label "status" in the bottom-right…
Hurdler
  • 823
  • 3
  • 15
  • 29
35
votes
8 answers

Resize a picture to fit a JLabel

I'm trying to make a picture fit a JLabel. I wish to reduce the picture dimensions to something more appropriate for my Swing JPanel. I tried with setPreferredSize but it doesn't work. I'm wondering if there is a simple way to do it? Should I…
user1680212
34
votes
1 answer

Jlabel color change

I tried to change the color of a jlabel in java netbeans I need a code to change the jLabel color Like: JLabel.SetColor(Color.RED);
user2255507
28
votes
2 answers

Underlined JLabel

I am trying to make a JLabel underlined. I searched everywhere, but I got nothing. Even in the properties, there is no option for underlining the JLabel. What can I do?
user2258850
27
votes
7 answers

Java: Linebreaks in JLabels?

I'm trying to make a Swing JLabel with multiple lines of text. It's added just fine, but the line breaks don't come through. How do I do this? Alternatively, can I just specify a maximum width for a JLabel and know that the text would wrap, like in…
Nick Heiner
  • 108,809
  • 177
  • 454
  • 689
25
votes
5 answers

Java: how to add image to Jlabel?

Image image = GenerateImage.toImage(true); //this generates an image file JLabel thumb = new JLabel(); thumb.setIcon(image)
KJW
  • 14,248
  • 44
  • 128
  • 236
1
2 3
99 100