Java Documentation

Core Swing Components

This section introduces the most frequently used Swing components— containers like JFrame and JPanel, and controls like buttons, labels, and text fields—that together form the building blocks of Java desktop applications.

Start with Setup

Before writing component-specific programs, make sure your development environment is ready for GUI work (JDK installed, editor configured, and Swing project created). Follow the step-by-step setup guide first.

Start with Setup

Recommended reading order: Setup → JFrame → JPanel → other components.

High-level View of Swing Components

In Swing, every visible element on the screen is a component. Some components act as top-level windows, some group other components, and some allow user interaction (typing, clicking, selecting). The following cards give you a quick overview and link to detailed pages.

How Components Work Together

In a typical Swing application, you create a JFrame as the main window, set a layout manager, and then add JPanels and other components inside it. Each component is responsible for a specific part of the user interface, but they all share a common event-driven programming model.

  • JFrame provides the window; JPanel organizes groups of components.
  • Labels, buttons, and text components live inside panels and respond to user actions.
  • Event listeners (explained later) connect user actions to Java code that performs some work.