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

3264 questions
24
votes
5 answers

How to change the mouse pointer to finger pointer in swing?

In html when we create a hyperlink and point over it ,then it automatically changes to a finger pointer. So I was wondering can we achieve the same in java swings. Suppose I have a label on clicking which a new form pops-up.But I want that when the…
Abhinav
  • 1,720
  • 4
  • 21
  • 33
21
votes
3 answers

Java: vertical alignment within JPanel

I am trying to vertically align (center) both JLabels inside one JPanel. JPanel panel = new JPanel(); panel.setPreferredSize(size); JLabel label1 = new JLabel(icon); JLabel label2 = new JLabel("text"); panel.add(label1); panel.add(label2); I have…
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
20
votes
5 answers

Draw a JButton to look like a JLabel (or at least without the button edge?)

I've got a JButton that for various reasons I want to act like a button, but look like a JLabel. It doesn't actually have to be a JLabel under the hood, I just don't want the raised button edge to show up. Is there an easy way to turn off the…
Electrons_Ahoy
  • 36,743
  • 36
  • 104
  • 127
18
votes
6 answers

find out if text of JLabel exceeds label size

In Java when the text of the JLabel could not be displayed due to lack of space the text is truncated and "..." is added in the end. How can I easily find out if currently JLabel displays full text or the truncated? EDIT: I see that there is a way…
jutky
  • 3,895
  • 6
  • 31
  • 45
18
votes
2 answers

JLabel vertical alignment not working as expected

Font font = Font("Arial", Font.BOLD, 35); JLabel label = new JLabel("57"); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); panel.add(label); This creates a JLabel with an extra space above and below it. I…
arpanoid
  • 2,123
  • 4
  • 17
  • 15
18
votes
6 answers

How do I put html in a JLabel in java?

How do I use html tags in a JLabel in java?
The Java Man
  • 295
  • 1
  • 2
  • 7
17
votes
5 answers

access to variable within inner class in java

I'm trying to create an array of JLabels, all of them should go invisible when clicked. The problem comes when trying to set up the mouse listener through an inner class that needs access to the iteration variable of the loop used to declare the…
Oscar Wahltinez
  • 1,155
  • 3
  • 12
  • 24
16
votes
1 answer

How to put the text of a JLabel under its icon

I trying to put the text of a JLabel under its icon (centered) at the momemnt I can get this using JLabel north = new JLabel("North") I tried using html in the label JLabel("
North") but it is not aligned properly. Any…
Bilal Syed Hussain
  • 8,664
  • 11
  • 38
  • 44
16
votes
4 answers

How to disable the automatic HTML support of JLabel?

A Swing JLabel automatically interprets any text as HTML content, if it starts with . If the content of this HTML is an image with invalid URL this will cause the whole GUI to hang since the ImageFetche which should load this image will quit…
tigger
  • 1,856
  • 3
  • 18
  • 23
16
votes
4 answers

How to set fix size of jlabel?

I am trying to make a java desktop application where I am using multiple JLabel I want to set fix height and width of JLabel. How can I achieve this? Here is my code public class Second extends JFrame { JPanel panel1,panel2; JLabel…
user3506824
  • 205
  • 1
  • 3
  • 7
16
votes
4 answers

how to center JLabel in Jframe Swing?

I have this working code for a stop watch in Swing. I want to have the label Time Remaining 300 seconds centered on the second line`. here is my code. import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Toolkit; import…
brain storm
  • 30,124
  • 69
  • 225
  • 393
15
votes
5 answers

Centering a JLabel on a JPanel

I'm using the NetBeans GUI builder to handle my layout (I'm terrible with LayoutManagers) and am trying to place a simple JLabel so that it is always centered (horizontally) inside its parent JPanel. Ideally, this would maintain true even if the…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
15
votes
7 answers

Simple Dropdown menu in Java

I am working on a very simple GUI in Java. In this GUI I want to display: A label with some text on the top of the page A JComboBox under the mentioned label A JButton under the mentioned JComboBox Here's my code: import…
NoobNe0
  • 385
  • 1
  • 6
  • 20
15
votes
5 answers

Clicking a JLabel to open a new frame

I am designing the graphics for a game i am programming, i wanted to know if there is an easy way of opening a frame when a JLabel is cliked? Is there easy code for this?
user1992697
  • 315
  • 1
  • 5
  • 11
14
votes
1 answer

How to set padding at JLabel

I want to display a Multiline JLabel into JPanel. So I have this code but I'm not able to show the multiline JLabel. public class NotificationFrame extends JFrame{ public NotificationFrame(){ JPanel panelBody = new JPanel(); …
bircastri
  • 2,169
  • 13
  • 50
  • 119