Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Using Swing Components

Using Intermediate Swing Containers

This section describes the Swing components that exist solely to contain other components. Technically, menu bars fall into this category, but those are discussed elsewhere, in the How to Use Menus section. To use intermediate containers, you should understand the concepts presented in Swing Components and the Containment Hierarchy(in the Creating a User Interface trail).

[PENDING: discuss layout managers and add() somewhere?]

Panels are the most general purpose, frequently used intermediate containers. Implemented with the JPanel class, panels add almost no functionality beyond what all JComponent objects have. They're often used to group components, whether because the components are related or just because grouping them makes layout easier. A panel can use any layout manager, and you can easily give it a border.

Four other Swing containers -- scroll panes, split panes, tabbed panes, and tool bars -- provide more functionality. A scroll pane provides scroll bars around a single component. A split pane lets the user customize the relative amount of space devoted to each of two components. A tabbed pane shows just one component at a time, letting you easily switch between components. A tool bar holds a group of components (usually buttons) in a row or column, and optionally allows the user to drag the tool bar into different locations.

The rest of the Swing intermediate containers are even more specialized. Internal frames look like frames and have much the same API, but unlike frames they must appear within other windows. Root panes provide behind-the-scenes support to top-level containers. Layered panes exist to support Z ordering of components.


Previous | Next | Trail Map | Creating a GUI with JFC/Swing | Using Swing Components