Labels

The JLabel class allows you to add basic, noninteractive labels to a user interface. Because of its inherent simplicity, there is no model class for JLabel.JLabel objects may consist of both text and graphics (icons), but for simple text-only labels, the interface with JLabel is very similar to that of java.awt.Label. The code to create and display a very simple text label looks like this:

import javax.swing.*;

public class SimpleJLabelExample {
	public static void main(String[] args) {
		JLabel label = new JLabel("Hello Label");

		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(label); // Adds to CENTER
		frame.pack();
		frame.setVisible(true);
	}
}