JLabels
Java Swing Tutorial Explaining the JLabel Component. JLabel, descended from JComponent, is used to
create text labels.
A JLabel object provides text instructions or information on a GUI — display a single line of read-only text, an image or both text and image.
We use a Swing JLabel when we need a user interface component that displays a message or an image.
JØLabels
create text labels.
A JLabel object provides text instructions or information on a GUI — display a single line of read-only text, an image or both text and image.
We use a Swing JLabel when we need a user interface component that displays a message or an image.
JØLabels
- Provide text instructions on a GUI
- lRead-only text
- lPrograms rarely change a label’s contents
- lClass JLabel (subclass of JComponent)
JLabel Source Code
import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.ImageIcon; public class JlabelDemo extends JPanel { JLabel jlbLabel1, jlbLabel2, jlbLabel3; public JlabelDemo() { ImageIcon icon = new ImageIcon("java-swing-tutorial.JPG", "My Website"); // Creating an Icon setLayout(new GridLayout(3, 1)); // 3 rows, 1 column Panel having Grid Layout jlbLabel1 = new JLabel("Image with Text", icon, JLabel.CENTER); // We can position of the text, relative to the icon: jlbLabel1.setVerticalTextPosition(JLabel.BOTTOM); |
Output
Download jLabel Source Code
Java JLabel Hierarchy
javax.swing
Class JLabel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
Class JLabel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable, SwingConstants
Direct Known Subclasses:
BasicComboBoxRenderer, DefaultListCellRenderer, DefaultTableCellRenderer, DefaultTreeCellRenderer
Accessible, ImageObserver, MenuContainer, Serializable, SwingConstants
Direct Known Subclasses:
BasicComboBoxRenderer, DefaultListCellRenderer, DefaultTableCellRenderer, DefaultTreeCellRenderer
JLabel Constructor
JLabel()
Creates a JLabel instance with no image and with an empty string for the title.
Creates a JLabel instance with no image and with an empty string for the title.
JLabel(Icon image)
Creates a JLabel instance with the specified image.
Creates a JLabel instance with the specified image.
JLabel(Icon image, int horizontalAlignment)
Creates a JLabel instance with the specified image and horizontal alignment.
Creates a JLabel instance with the specified image and horizontal alignment.
JLabel(String text)
Creates a JLabel instance with the specified text.
Creates a JLabel instance with the specified text.
JLabel(String text, Icon icon, int horizontalAlignment)
Creates a JLabel instance with the specified text, image, and horizontal alignment.
Creates a JLabel instance with the specified text, image, and horizontal alignment.
JLabel(String text, int horizontalAlignment)
Creates a JLabel instance with the specified text and horizontal alignment.
Creates a JLabel instance with the specified text and horizontal alignment.
0 comments:
Post a Comment