Typical Swing applications do processing in response to an event generated
from a user gesture. For example, clicking on a JButton notifies all
ActionListeners added to the JButton. As all events generated
from a user gesture are dispatched on the event dispatching thread, most
developers are not impacted by the restriction.
Where the impact lies, however, is in constructing and showing a Swing
application. Calls to an application's main method,
are not invoked on the event dispatching thread. As such,
care must be taken to transfer control to the event dispatching thread when
constructing and showing an application. The preferred way to
transfer control and begin working with Swing is to use invokeLater.
The invokeLater method schedules a Runnable to be processed
on the event dispatching thread. The following two examples work equally well
for transferring control and starting up a Swing application:
import javax.swing.SwingUtilities;
public class MyApp implements Runnable {
public void run() {
// Invoked on the event dispatching thread.
// Construct and show GUI.
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new MyApp());
}
}
Or:
import javax.swing.SwingUtilities;
public class MyApp {
MyApp(String[] args) {
// Invoked on the event dispatching thread.
// Do any initialization here.
}
public void show() {
// Show the UI.
}
public static void main(final String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyApp(args).show();
}
});
}
}
This restriction also applies to models attached to Swing components. For
example, if a TableModel is attached to a JTable, the
TableModel should only be modified on the event dispatching thread.
If you modify the model on a separate thread you run the risk of exceptions
and possible display corruption.
Although it is generally safe to make updates to the UI immediately,
when executing on the event dispatch thread, there is an exception :
if a model listener tries to further change the UI before the UI has been
updated to reflect a pending change then the UI may render incorrectly.
This can happen if an application installed listener needs to update the UI
in response to an event which will cause a change in the model structure.
It is important to first allow component installed listeners to process this
change, since there is no guarantee of the order in which listeners may be
called.
The solution is for the application listener to make the change using
javax. so that any changes
to UI rendering will be done post processing all the model listeners
installed by the component.
As all events are delivered on the event dispatching thread, care must be
taken in event processing. In particular, a long running task, such as
network io or computational intensive processing, executed on the event
dispatching thread blocks the event dispatching thread from dispatching any
other events. While the event dispatching thread is blocked the application
is completely unresponsive to user input. Refer to
javax. for the preferred way to do such processing
when working with Swing.
More information on this topic can be found in the Swing tutorial, in particular the section on Concurrency in Swing.
Warning
Serialized objects of any Swing class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans has been added to the java.beans package.
| Modifier and Type | Interface and Description |
|---|---|
| public interface | Action
The |
| public interface | BoundedRangeModel
Defines the data model used by components like |
| public interface | ButtonModel
State model for buttons. |
| public interface | CellEditor
This interface defines the methods any general editor should be able to implement. |
| public interface | ComboBoxEditor
The editor component used for JComboBox components. |
| public interface | |
| public interface | DesktopManager
DesktopManager objects are owned by a JDesktopPane object. |
| pack-priv interface | |
| public interface | Icon
A small fixed size picture, typically used to decorate components. |
| public interface | ListCellRenderer<
the type of values this renderer can be used for E>Identifies components that can be used as "rubber stamps" to paint the cells in a JList. |
| public interface | ListModel<
the type of the elements of this model E>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. |
| public interface | ListSelectionModel
This interface represents the current state of the selection for any of the components that display a list of values with stable indices. |
| public interface | MenuElement
Any component that can be placed into a menu should implement this interface. |
| public interface | |
| public interface | |
| public interface | Renderer
Defines the requirements for an object responsible for "rendering" (displaying) a value. |
| public interface | RootPaneContainer
This interface is implemented by components that have a single JRootPane child: JDialog, JFrame, JWindow, JInternalFrame. |
| public interface | Scrollable
An interface that provides information to a scrolling container like JScrollPane. |
| public interface | ScrollPaneConstants
Constants used with the JScrollPane component. |
| public interface | SingleSelectionModel
A model that supports at most one indexed selection. |
| public interface | SpinnerModel
A model for a potentially unbounded sequence of object values. |
| public interface | SwingConstants
A collection of constants generally used for positioning and orienting components on the screen. |
| pack-priv interface | SwingHeavyWeight
An interface used to tag heavy weight components that we want processed by Swing's RepaintManager. |
| public interface | UIClientPropertyKey
This interface is used only for tagging keys for client properties for
|
| public interface | WindowConstants
Constants used to control the window-closing operation. |
| Modifier and Type | Annotation and Description |
|---|---|
| public @interface | SwingContainer
An annotation used to specify some swing-related information
for the automatically generated |
| Modifier and Type | Class and Description |
|---|---|
| public abstract class | AbstractAction
This class provides default implementations for the JFC |
| public abstract class | AbstractButton
Defines common behaviors for buttons and menu items. |
| public abstract class | AbstractCellEditor
A base class for |
| public abstract class | AbstractListModel<
the type of the elements of this model E>The abstract definition for the data model that provides
a |
| public abstract class | AbstractSpinnerModel
This class provides the ChangeListener part of the SpinnerModel interface that should be suitable for most concrete SpinnerModel implementations. |
| public class | ActionMap
|
| pack-priv abstract class | ActionPropertyChangeListener<
the type of JComponent the underlying Action is attached to T extends JComponent>A package-private PropertyChangeListener which listens for property changes on an Action and updates the properties of an ActionEvent source. |
| pack-priv class | |
| pack-priv class | |
| pack-priv class | Autoscroller
Autoscroller is responsible for generating synthetic mouse dragged events. |
| public class | BorderFactory
Factory class for vending standard |
| public class | Box
A lightweight container that uses a BoxLayout object as its layout manager. |
| public class | BoxLayout
A layout manager that allows multiple components to be laid out either vertically or horizontally. |
| pack-priv class | BufferStrategyPaintManager
A PaintManager implementation that uses a BufferStrategy for rendering. |
| public class | ButtonGroup
This class is used to create a multiple-exclusion scope for a set of buttons. |
| public class | CellRendererPane
This class is inserted in between cell renderers and the components that use them. |
| pack-priv class | |
| pack-priv class | |
| pack-priv class | |
| public class | ComponentInputMap
A |
| public class | DebugGraphics
Graphics subclass supporting graphics debugging. |
| pack-priv class | DebugGraphicsFilter
Color filter for DebugGraphics, used for images only. |
| pack-priv class | DebugGraphicsInfo
Class used by DebugGraphics for maintaining information about how to render graphics calls. |
| pack-priv class | DebugGraphicsObserver
ImageObserver for DebugGraphics, used for images only. |
| public class | DefaultBoundedRangeModel
A generic implementation of BoundedRangeModel. |
| public class | DefaultButtonModel
The default implementation of a |
| public class | DefaultCellEditor
The default editor for table and tree cells. |
| public class | |
| public class | DefaultDesktopManager
This is an implementation of the |
| public class | DefaultFocusManager
This class has been obsoleted by the 1.4 focus APIs. |
| public class | DefaultListCellRenderer
Renders an item in a list. |
| public class | DefaultListModel<
the type of the elements of this model E>This class loosely implements the |
| public class | DefaultListSelectionModel
Default data model for list selections. |
| public abstract class | DefaultRowSorter<
the type of the model M, the type of the identifier passed to the I>RowFilterAn implementation of |
| public class | DefaultSingleSelectionModel
A generic implementation of SingleSelectionModel. |
| pack-priv class | DelegatingDefaultFocusManager
Provides a javax.swing.DefaultFocusManager view onto an arbitrary java.awt.KeyboardFocusManager. |
| public abstract class | FocusManager
This class has been obsoleted by the 1.4 focus APIs. |
| public class | GrayFilter
An image filter that "disables" an image by turning it into a grayscale image, and brightening the pixels in the image. |
| public class | GroupLayout
|
| public class | ImageIcon
An implementation of the Icon interface that paints Icons from Images. |
| public class | InputMap
|
| public abstract class | InputVerifier
This class provides the validation mechanism for Swing components. |
| public abstract class | InternalFrameFocusTraversalPolicy
A FocusTraversalPolicy which can optionally provide an algorithm for determining a JInternalFrame's initial Component. |
| public class | JButton
An implementation of a "push" button. |
| public class | JCheckBox
An implementation of a check box -- an item that can be selected or deselected, and which displays its state to the user. |
| public class | JCheckBoxMenuItem
A menu item that can be selected or deselected. |
| public class | JColorChooser
|
| public class | JComboBox<
the type of the elements of this combo box E>A component that combines a button or editable field and a drop-down list. |
| public abstract class | JComponent
The base class for all Swing components except top-level containers. |
| public class | JDesktopPane
A container used to create a multiple-document interface or a virtual desktop. |
| public class | JDialog
The main class for creating a dialog window. |
| public class | JEditorPane
A text component to edit various kinds of content. |
| public class | JFileChooser
|
| public class | JFormattedTextField
|
| public class | JFrame
An extended version of |
| public class | 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. |
| public class | JLabel
A display area for a short text string or an image, or both. |
| public class | |
| public class | JLayeredPane
|
| public class | JList<
the type of the elements of this list E>A component that displays a list of objects and allows the user to select one or more items. |
| public class | JMenu
An implementation of a menu -- a popup window containing
|
| public class | JMenuBar
An implementation of a menu bar. |
| public class | JMenuItem
An implementation of an item in a menu. |
| public class | JOptionPane
|
| public class | JPanel
|
| public class | JPasswordField
|
| public class | JPopupMenu
An implementation of a popup menu -- a small window that pops up and displays a series of choices. |
| public class | JProgressBar
A component that visually displays the progress of some task. |
| public class | JRadioButton
An implementation of a radio button -- an item that can be selected or deselected, and which displays its state to the user. |
| public class | JRadioButtonMenuItem
An implementation of a radio button menu item. |
| public class | JRootPane
A lightweight container used behind the scenes by
|
| public class | JScrollBar
An implementation of a scrollbar. |
| public class | JScrollPane
Provides a scrollable view of a lightweight component. |
| public class | JSeparator
|
| public class | JSlider
A component that lets the user graphically select a value by sliding a knob within a bounded interval. |
| public class | JSpinner
A single line input field that lets the user select a number or an object value from an ordered sequence. |
| public class | JSplitPane
|
| public class | 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. |
| public class | JTable
The |
| public class | JTextArea
A |
| public class | JTextField
|
| public class | JTextPane
A text component that can be marked up with attributes that are represented graphically. |
| public class | JToggleButton
An implementation of a two-state button. |
| public class | JToolBar
|
| public class | JToolTip
Used to display a "Tip" for a Component. |
| public class | JTree
A control that displays a set of hierarchical data as an outline. |
| public class | JViewport
The "viewport" or "porthole" through which you see the underlying information. |
| public class | JWindow
A |
| pack-priv class | KeyboardManager
The KeyboardManager class is used to help dispatch keyboard actions for the WHEN_IN_FOCUSED_WINDOW style actions. |
| public class | KeyStroke
A KeyStroke represents a key action on the keyboard, or equivalent input device. |
| pack-priv class | LayoutComparator
Comparator which attempts to sort Components based on their size and position. |
| public class | LayoutFocusTraversalPolicy
A SortingFocusTraversalPolicy which sorts Components based on their size, position, and orientation. |
| public abstract class | LayoutStyle
|
| pack-priv class | LegacyGlueFocusTraversalPolicy
A FocusTraversalPolicy which provides support for legacy applications which handle focus traversal via JComponent.setNextFocusableComponent or by installing a custom DefaultFocusManager. |
| pack-priv class | |
| public abstract class | LookAndFeel
|
| public class | MenuSelectionManager
A MenuSelectionManager owns the selection in menu hierarchy. |
| pack-priv class | |
| public class | OverlayLayout
A layout manager to arrange components over the top of each other. |
| public class | Popup
Popups are used to display a |
| public class | PopupFactory
|
| public class | ProgressMonitor
A class to monitor the progress of some operation. |
| public class | ProgressMonitorInputStream
Monitors the progress of reading from some InputStream. |
| public class | 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. |
| public abstract class | RowFilter<
the type of the model; for example M, PersonModelthe type of the identifier; when using
I>TableRowSorter this will be Integer
|
| public abstract class | |
| public class | ScrollPaneLayout
The layout manager used by |
| public class | SizeRequirements
For the convenience of layout managers, calculates information about the size and position of components. |
| public class | SizeSequence
A |
| public class | SortingFocusTraversalPolicy
A FocusTraversalPolicy that determines traversal order by sorting the Components of a focus traversal cycle based on a given Comparator. |
| public class | SpinnerDateModel
A |
| public class | SpinnerListModel
A simple implementation of |
| public class | SpinnerNumberModel
A |
| public abstract class | Spring
An instance of the |
| public class | SpringLayout
A |
| pack-priv class | |
| pack-priv class | |
| pack-priv class | SwingPaintEventDispatcher
Swing's PaintEventDispatcher. |
| public class | SwingUtilities
A collection of utility methods for Swing. |
| public abstract class | SwingWorker<
the result type returned by this T, SwingWorker's
doInBackground and get methodsthe type used for carrying out intermediate results by this
V>SwingWorker's publish and process methodsAn abstract class to perform lengthy GUI-interaction tasks in a background thread. |
| pack-priv class | TablePrintable
An implementation of |
| public class | Timer
Fires one or more |
| pack-priv class | TimerQueue
Internal class to manage all Timers using one thread. |
| public class | ToolTipManager
Manages all the |
| public class | TransferHandler
This class is used to handle the transfer of a |
| public class | UIDefaults
A table of defaults for Swing components. |
| public class | UIManager
|
| public class | UnsupportedLookAndFeelException
An exception that indicates the requested look & feel management classes are not present on the user's system. |
| public class | ViewportLayout
The default layout manager for |
| Modifier and Type | Enum and Description |
|---|---|
| pack-priv enum | ClientPropertyKey
An enumeration for keys used as client properties within the Swing implementation. |
| public enum | DropMode
Drop modes, used to determine the method by which a component tracks and indicates a drop location during drag and drop. |
| public enum | SortOrder
SortOrder is an enumeration of the possible sort orderings. |