- A JLabel represents a label, i.e. a display area for non-editable text.
- A JLabel can display both text and images.
- It can even render HTML tags so that you can create a JLabel that displays multicolors or multiline text.
The javax.swing.JLabel class has the following constructors.
public JLabel ()
public JLabel (java.lang.String text)
public JLabel (java.lang.String text, int horizontalAlignment)
public JLabel (Icon image)
public JLabel (Icon image, int horizontalAlignment)
public JLabel (Java.lang.String text, Icon icon, int horizontalAlignment)
The value of horizontalAlignment is one of the following:
- SwingConstants.LEFT
- SwingConstants.CENTER
- SwingConstants.RIGHT
- SwingConstants.LEADING
- SwingConstants.TRAILING
If you want to use multifonts or multicolors in a JLabel, you can pass HTML tags,
A JLabel subclass is used as the default renderer for each of the JList,
JComboBox, JTable, and JTree components.
Alignments have an effect only if there's extra space for the layout manager to position the component.