JavaTM 2 Platform
Std. Ed. v1.3.1

Package javax.swing

Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms.

See:
          Description

Interface Summary
Action The Action interface provides a useful extension to the ActionListener interface in cases where the same functionality may be accessed by several controls.
BoundedRangeModel Defines the data model used by components like Sliders and ProgressBars.
ButtonModel State Model for buttons.
CellEditor This interface defines the methods any general editor should be able to implement.
ComboBoxEditor The editor component used for JComboBox components.
ComboBoxModel ComboBoxDataModel is a ListDataModel with a selected item This selected item is in the model since it is not always in the item list.
DesktopManager DesktopManager objects are owned by a JDesktopPane object.
Icon A small fixed size picture, typically used to decorate components.
JComboBox.KeySelectionManager The interface that defines a KeySelectionManager.
ListCellRenderer Identifies components that can be used as "rubber stamps" to paint the cells in a JList.
ListModel This interface defines the methods components like JList use to get the value of each cell in a list and the length of the list.
ListSelectionModel This interface represents the current state of the selection for any of the components that display a list of values with stable indices.
MenuElement Any component that can be placed into a menu should implement this interface.
MutableComboBoxModel A mutable version of ComboBoxModel.
Renderer Defines the requirements for an object responsible for "rendering" (displaying) a value.
RootPaneContainer This interface is implemented by components that have a single JRootPane child: JDialog, JFrame, JWindow, JApplet, JInternalFrame.
Scrollable An interface that provides information to a scrolling container like JScrollPane.
ScrollPaneConstants Constants used with the JScrollPane component.
SingleSelectionModel A model that supports at most one indexed selection.
SwingConstants A collection of constants generally used for positioning and orienting components on the screen.
UIDefaults.ActiveValue This class enables one to store an entry in the defaults table that's constructed each time it's looked up with one of the getXXX(key) methods.
UIDefaults.LazyValue This class enables one to store an entry in the defaults table that isn't constructed until the first time it's looked up with one of the getXXX(key) methods.
WindowConstants Constants used to control the window-closing operation.
 

Class Summary
AbstractAction This class provides default implementations for the JFC Action interface.
AbstractButton Defines common behaviors for buttons and menu items.
AbstractCellEditor  
AbstractListModel The Abstract definition for the data model the provides a List with its contents.
ActionMap ActionMap provides mappings from Objects (called keys or Action names) to Actions.
BorderFactory Factory class for vending standard Border objects.
Box A lightweight container that uses a BoxLayout object as its layout manager.
Box.Filler An implementation of a lightweight component that participates in layout but has no view.
BoxLayout A layout manager that allows multiple components to be layed out either vertically or horizontally.
ButtonGroup This class is used to create a multiple-exclusion scope for a set of buttons.
CellRendererPane This class is inserted in between cell renderers and the components that use them.
ComponentInputMap A ComponentInputMap is an InputMap associated with a particular JComponent.
DebugGraphics Graphics subclass supporting graphics debugging.
DefaultBoundedRangeModel A generic implementation of BoundedRangeModel.
DefaultButtonModel The default implementation of a Button component's data model.
DefaultCellEditor The default editor for table and tree cells.
DefaultComboBoxModel The default model for combo boxes.
DefaultDesktopManager This is an implementaion of the DesktopManager.
DefaultFocusManager Default swing focus manager implementation.
DefaultListCellRenderer Renders an item in a list.
DefaultListCellRenderer.UIResource A subclass of DefaultListCellRenderer that implements UIResource.
DefaultListModel This class implements the java.util.Vector API and notifies the ListDataListeners when changes occur.
DefaultListSelectionModel Default data model for list selections.
DefaultSingleSelectionModel A generic implementation of SingleSelectionModel.
FocusManager Swing Focus Manager
GrayFilter An image filter that "disables" an image by turning it into a grayscale image, and brightening the pixels in the image.
ImageIcon An implementation of the Icon interface that paints Icons from Images.
InputMap InputMap provides a binding between an input event (currently only KeyStrokes are used) and an Object.
InputVerifier The purpose of this class is to help clients support smooth focus navigation through GUIs with text fields.
JApplet An extended version of java.applet.Applet that adds support for the JFC/Swing component architecture.
JButton An implementation of a "push" button.
JCheckBox An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user.
JCheckBoxMenuItem A menu item that can be selected or deselected.
JColorChooser JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color.
JComboBox A component that combines a button or text field and a drop-down list.
JComponent The base class for all Swing components except top-level containers.
JDesktopPane A container used to create a multiple-document interface or a virtual desktop.
JDialog The main class for creating a dialog window.
JEditorPane A text component to edit various kinds of content.
JFileChooser JFileChooser provides a simple mechanism for the user to choose a file.
JFrame An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture.
JInternalFrame A lightweight object that provides many of the features of a native frame, including dragging, closing, becoming an icon, resizing, title display, and support for a menu bar.
JInternalFrame.JDesktopIcon This component represents an iconified version of a JInternalFrame.
JLabel A display area for a short text string or an image, or both.
JLayeredPane JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed.
JList A component that allows the user to select one or more objects from a list.
JMenu An implementation of a menu -- a popup window containing JMenuItems that is displayed when the user selects an item on the JMenuBar.
JMenuBar An implementation of a menu bar.
JMenuItem An implementation of an item in a menu.
JOptionPane JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something.
JPanel JPanel is a generic lightweight container.
JPasswordField JPasswordField is a lightweight component that allows the editing of a single line of text where the view indicates something was typed, but does not show the original characters.
JPopupMenu An implementation of a popup menu -- a small window that pops up and displays a series of choices.
JPopupMenu.Separator A popup menu-specific separator.
JProgressBar A component that displays an integer value within a bounded interval.
JRadioButton An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user.
JRadioButtonMenuItem An implementation of a radio button menu item.
JRootPane A lightweight container used behind the scenes by JFrame, JDialog, JWindow, JApplet, and JInternalFrame.
JScrollBar An implementation of a scrollbar.
JScrollPane Provides a scrollable view of a component.
JSeparator An implementation of a menu separator -- a divider between menu items that breaks them up into logical groupings.
JSlider A component that lets the user graphically select a value by slding a knob within a bounded interval.
JSplitPane JSplitPane is used to divide two (and only two) Components.
JTabbedPane A component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon.
JTable JTable is a user-interface component that presents data in a two-dimensional table format.
JTextArea A TextArea is a multi-line area that displays plain text.
JTextField JTextField is a lightweight component that allows the editing of a single line of text.
JTextPane A text component that can be marked up with attributes that are represented graphically.
JToggleButton An implementation of a two-state button.
JToggleButton.ToggleButtonModel The ToggleButton model
JToolBar JToolBar provides a component that is useful for displaying commonly used Actions or controls.
JToolBar.Separator A toolbar-specific separator.
JToolTip Used to display a "Tip" for a Component.
JTree A control that displays a set of hierarchical data as an outline.
JTree.DynamicUtilTreeNode DynamicUtilTreeNode can wrap vectors/hashtables/arrays/strings and create the appropriate children tree nodes as necessary.
JTree.EmptySelectionModel EmptySelectionModel is a TreeSelectionModel that does not allow anything to be selected.
JViewport The "viewport" or "porthole" through which you see the underlying information.
JWindow A JWindow is a container that can be displayed anywhere on the user's desktop.
KeyStroke A KeyStroke instance represents a key being typed on the keyboard -- it contains both a char code for the key and a modifier (alt, shift, ctrl, meta, or a combination).
LookAndFeel Completely characterizes a look and feel from the point of view of the pluggable look and feel components.
MenuSelectionManager A MenuSelectionManager owns the selection in menu hierarchy.
OverlayLayout A layout manager to arrange components over the top of each other.
ProgressMonitor A class to monitor the progress of some operation.
ProgressMonitorInputStream Monitors the progress of reading from some InputStream.
RepaintManager This class manages repaint requests, allowing the number of repaints to be minimized, for example by collapsing multiple requests into a single repaint for members of a component tree.
ScrollPaneLayout The layout manager used by JScrollPane.
ScrollPaneLayout.UIResource The UI resource version of ScrollPaneLayout.
SizeRequirements For the convenience of layout managers, calculates information about the size and position of components.
SizeSequence A SizeSequence object efficiently maintains an ordered list of sizes and corresponding positions.
SwingUtilities A collection of utility methods for Swing.
Timer Causes an action to occur at a predefined rate.
ToolTipManager Manages all the ToolTips in the system.
UIDefaults A table of defaults for Swing components.
UIDefaults.LazyInputMap LazyInputMap will create a InputMap in its createValue method.
UIDefaults.ProxyLazyValue This class provides an implementation of LazyValue which can be used to delay loading of the Class for the instance to be created.
UIManager This class keeps track of the current look and feel and its defaults.
UIManager.LookAndFeelInfo Provide a little information about an installed LookAndFeel for the sake of configuring a menu or for initial application set up.
ViewportLayout The default layout manager for JViewport.
 

Exception Summary
UnsupportedLookAndFeelException An exception that indicates the request look & feel management classes are not present on the user's system.
 

Package javax.swing Description

Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms. For a programmer's guide to using these components, see Creating a GUI with JFC/Swing, a trail in The Java Tutorial. For other resources, see Related Documentation.

The Swing architecture provides a number of advantages in the areas of:

Wide Variety of Components

In general, the class names that start with "J" are the components you add to an application. Examples: JButton, JLabel, JList, JPanel, JTable, JTree. The remaining files in the swing package contain the utility classes and interfaces that the components use to function.

Pluggable Look and Feel

Instead of being restricted to a single "look and feel", you can select a look and feel and "plug it in". An interface made of Swing components can look like a Win32 app, a Motif app, or a Mac app. It can use the new "Metal" look and feel. Developers can use standard Swing components and design their own look and feel (L&F) for them, and even allow users to select the look and feel they prefer. The plaf package includes the standard "Pluggable Look And Feel" classes.

MVC Architecture

The Model-View-Controller (MVC) architecture is used consistently throughout the Swing component set. The View and Controller parts of the architecture are combined in the component. Each component has an associated Model class and an interface it uses. You can provide your own data-model for a component by subclassing the Model class or by implementing the appropriate interface. For example, you could subclass DefaultListModel or implement the ListModel interface, and then use the JList setModel method to attach your data-model to the component.

Keystroke Handling

The JComponent architecture makes it easy to handle keyboard events in nested components. You register interest in a particular combination of keystrokes by creating a KeyStroke object and registering it with the component. When you register the keystroke combination and its associated action, you also specify one of the following conditions to determine when the action is initiated:

For an index of the default keystroke behaviors for the Swing components in each of the standard Look and Feel implementations, see Swing Component Keystroke Assignments.

Action Objects

Action-interface objects provide a single point of control for program actions. For example, a toolbar icon and a menu item can reference the same Action object. When the Action object is disabled, the GUI items that reference it are automatically disabled. The Action interface extends ActionListener, specifying an enabled property as well as properties for text-descriptions and graphic icons.

Nested Containers

As the keystroke handling shows, Swing was designed to manage nested containers gracefully. The main "heavyweight" containers (JWindow, JFrame, JDialog, and JApplet) as well as the major "lightweight" containers (JInternalFrame and JComponent) all delegate their operations to a JRootPane. This commonality produces a high degree of regularity in container nesting. In particular, since the fundamental component class (JComponent) contains a JRootPane, virtually any component can be nested within another. It means, for example, that a graphic can be nested in a list, and a combo box can be nested in a toolbar. The JRootPane class uses a JLayeredPane to manage a content pane and an optional menu bar in a way that is virtually transparent to the developer. It also provides for a glass pane -- a single pane that can overlap multiple containers and be used for drawing or to intercept mouse actions.

Virtual Desktops

The JDesktopPane and JInternalFrame classes can be used to create a virtual desktop, or "multiple document interface". A JInternalFrame can be specified as iconizable, exandable, or closable, while the JDesktopPane provides real estate for them to operate in.

Compound Borders

Insets (the space between the edges of the component and the area it is drawn in) can be specified with a blank border. In addition, many border styles are available, which can be combined to create compound borders.

Customized Dialogs

The JOptionPane class provides a variety of static methods that you can invoke to create and display both message dialogs and user-choice dialogs in a variety of formats. The "message" displayed in the dialog can be a string, a string-generating object, or an arbitrary component. You can also replace the choice-buttons with components you specify for user-selections.

For example, the following line creates a simple message dialog that requires the user's confirmation:

JOptionPane.showMessageDialog(null, "The file will be deleted.");

Additional options for customized dialogs are described in the JOptionPane class.

Standard Dialog Classes

Standard dialogs currently available include:

And more standard dialogs are on the way.

Structured Table and Tree Components

The JTable class provides a data-aware matrix. JTree provides hierarchical-structuring of data elements.

Powerful Text Manipulations

In addition to single-font text fields and text areas, Swing provides a JPassword field for hidden input and a JTextPane class for displaying multi-font text. In addition, the JEditorPane class provides editing capabilities for multi-font text, while the text.html and text.rtf packages handle text encoded in HyperText Markup Language (HTML) or Rich Text Format (RTF).

Generic Undo Capabilities

The undo package provides generic undo capabilities that can be used in a variety of situations.

Accessibility Support

Swing has built-in support for developers to make products that are compatible with Assistive Technologies (for alternative interfaces like, for example, braille.) All of the Swing components implement interface Accessible.

Related Documentation

For overviews, tutorials, examples, guides, and other documentation, please see:


JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Oracle and/or its affiliates, in the US and other countries.
Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.