5.3 JLabel and JButton
JLabel
- JLabel is a class
- represents a component for placing text in a container
- It is used to display a single line of read only text.
- The text can be changed by an application but a user cannot edit it directly.
- It inherits JComponent class.
- javax.swing.JLabel
- public class JLabel extends JComponent implements SwingConstants, Accessible
| JLabel Constructor | Description |
|---|---|
| JLabel( ) | Creates a JLabel instance with no image and with an empty string for the title. |
| JLabel (String s) | Creates a JLabel instance with the specified text. |
| JLabel (Icon i) | Creates a JLabel instance with the specified image. |
| JLabel(String s, Icon i, int horizontalAlignment) | Creates a JLabel instance with the specified text, image, and horizontal alignment. |
JLabel Class Methods:
Methods Description String getText() t returns the text string that a label displays. void setText(String text) It defines the single line of text this component will display. void setHorizontalAlignment(int alignment) It sets the alignment of the label's contents along the X axis. Icon getIcon() It returns the graphic image that the label displays. int getHorizontalAlignment() It returns the alignment of the label's contents along the X axis.