Java Swing![]() What is Java Swing![]() Swing Hello World![]() Swing Concepts![]() Swing Application, an Overview![]() Containment Hierarachy![]() Tasks![]() The JComponent Class![]() Basic Swing Components![]() Top Level Containers![]() JFrame![]() Intermediate Swing Containers![]() JPanel![]() Using Atomic Components![]() ImageIcon![]() Useful Automic Components![]() Layout Managers![]() GridBagLayout Class![]() GridBagConstraints![]() Using JScrollPane![]() Anatomy of a Swing Application Layout Manager Event Handling Inner Classes Swing Applet Exceptions Threads Java I/O Network Programming Resources | Swing Hello Worldimport javax.swing.*;
public class HelloWorldSwing {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
NoteThe pack method sizes the frame so that all its contents are at or above their preferred sizes. An alternative to pack is to establish a frame's size explicitly by calling setSize. The setVisible method makes the frame appear onscreen. The setDefaultCloseOperation method to configure the default action for when the user clicks the close button. See WindowConstants |