JLabel in Java Swing with Method Constructors and Examples

JLabel in Java Swing is an object that is used to display text and images in a Frame.

Jlabel uses to display information, show different messages, and make the frame interactive and readable.

JLabel class declaration

JLabel extends JComponent and implements SwingConstants and Accessible Interfaces.

JLabel Constructors

Sr NoConstructor and Description
1JLabel()
Create a Jlabel with no image and empty text
2JLabel​(String text)
Create a Jlabel with specified text
3JLabel​(String text, int horizontalAlignment)
Create a Jlabel with specified text and horizontalAlignment
4JLabel​(String text, Icon icon, int horizontalAlignment)
Create a Jlabel with specified text, image and horizontalAlignment
5JLabel​(Icon image)
Create a Jlabel with specified image
6JLabel​(Icon image, int horizontalAlignment)
Create a Jlabel with specified image and horizontalAlignment

Commonly used JLabel Methods

Sr NoMethod and Description
1String getText()
Get the text of label
2void setText​(String text)
Set the text of label
3Icon getIcon()
Return the Graphic Icon of label
4void setIcon​(Icon icon)
Set the graphic icon for label
5void setHorizontalAlignment​(int alignment)
Set Horizontal alignment of label
6int getHorizontalAlignment()
Get Horizontal alignment of label
5void setVerticalAlignment​(int alignment)
Set Vertical alignment of label
6int getVerticalAlignment()
Get Vertical alignment of label

JLabel contains more methods we have used a few of them here.

jlabel java Examples

jlabel java Examples

Label in java Example- How to change jlabel background color

JLabel Example – Foreground and background color change

Foreground and background color change

Jlabel set font Example Set JLable font Size, Font Height

jlabel set font Example

JLabel Example to getAttributes

How to Show Image in JLabel

Read More

  1. JComboBox in Java Swing
  2. JTable in Java Swing
  3. JTable Pagination in Java JDBC
  4. Registration Form in Java Swing
  5. Login form in Java Swing
  6. Simple Calculator in Java Applet
  7. Applet Life Cycle in Java

Read More

  1. JComboBox in Java Swing
  2. JTable in Java Swing
  3. JTable Pagination in Java JDBC
  4. Registration Form in Java Swing
  5. Login form in Java Swing
  6. Simple Calculator in Java Applet
  7. Applet Life Cycle in Java