Label and JLabel in AWT & Swing

Label

Labels are used for display purpose. It is a passive control i.e. it does not create any event or interaction with the user. It is used to display a single line read-only text.

Declaration of Label Class

public class Label
      extends Component
            implements Accessible

Label Class Constructors

ConstructorsDescription
Label()Constructs an empty label.
Label(String str)Constructs the new label with the specified string of text, left justified.
Label(String str, int alignment)Constructs a new label that represents specified string of text with the specified alignment.

JLabel


JLabel is used for display short text string or an image. JLabel extends from the JComponent class and implements the Accessible interface. It also provides the position of the text relative to the image.

Declaration of JLabel Class

public class JLabel
        extends JComponent
               implements SwingConstants, Accessible

JLabel Class Constructors

ConstructorsDescription
JLabel()Creates a JLabel instance with no image and with an empty string.
JLabel(Icon image)Create a JLabel with the specified image.
JLabel(Icon image, int horizontalAlignment)Creates a JLabel instance with the specified image and horizontal alignment.
JLabel(Stirng str)Creates a JLabel instance with the specified string.
JLabel(String str, Icon icon, int horizontalAlignment)Creates a JLabel instance with the specified string, image and horizontal alignment.
JLabel(String str, int horizontalAlignment)Create a JLabel instance with the specified text and horizontal alignment.