Java Platform 1.2

Package javax.swing

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


Interface Summary
Action The JFC Action interface provides a useful extension to the ActionListner 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 the common behaviors for the JButton, JToggleButton, JCheckbox, and the JRadioButton classes.
AbstractListModel The Abstract definition for the data model the provides a List with its contents.
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.
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 JListDataModel listeners 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.
JApplet An extended version of java.applet.Applet that adds support for interposing input and painting behavior in front of the applets children (see glassPane), support for special children that are managed by a LayeredPane (see rootPane) and for Swing MenuBars.
JButton An implementation of a "push" button.
JCheckBox An implementation of a CheckBox -- 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 Swing's implementation of a ComboBox -- a combination of a text field and drop-down list that lets the user either type in a value or select it from a list that is displayed when the user asks for it.
JComponent The base class for the Swing components.
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 chooser a file.
JFrame An extended version of java.awt.Frame that adds support for interposing input and painting behavior in front of the frame's children (see glassPane), support for special children that are managed by a LayeredPane (see rootPane) and for Swing MenuBars.
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 MenuBar.
JMenuItem An implementation of a MenuItem.
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 which pops up and displays a series of choices.
JPopupMenu.Separator A popupmenu-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 RadioButtonMenuItem.
JRootPane The fundamental component in the container hierarchy.
JScrollBar An implementation of a scrollbar.
JScrollPane A specialized container that manages a viewport, optional vertical and horizontal scrollbars, and optional row and column heading viewports.
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 which 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 Warning: Serialized objects of this class will not be compatible with future Swing releases.
JToolBar JToolBar provides a component which 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.
SwingUtilities A collection of utility methods for Swing.
Timer Object subclass that 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.
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. 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:


Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.