Program to demonstrate adding of a Label to a Swing component in Java.
Output of the program :
package com.hubberspot.awtSwing.example; import java.awt.*; import javax.swing.*; public class LabelDemo { JFrame frame; JLabel label1, label2, label3, label4; LabelDemo() { frame = new JFrame(); frame.setLayout(new GridLayout(4,1)); label1 = new JLabel(" Left Label "); label2 = new JLabel(" Center Label ", JLabel.CENTER); label3 = new JLabel(" Right Label", JLabel.RIGHT); label4 = new JLabel(" Image Label", new ImageIcon("c:\\smile.jpg"),JLabel.CENTER); frame.add(label1); frame.add(label2); frame.add(label3); frame.add(label4); frame.setTitle("Welcome to Hubberspot!."); frame.setSize(300,300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new LabelDemo(); } }
Output of the program :