The base class for all Swing components except top-level containers.
To use a component that inherits from JComponent,
you must place the component in a containment hierarchy
whose root is a top-level Swing container.
Top-level Swing containers --
such as JFrame, JDialog,
and JApplet --
are specialized components
that provide a place for other Swing components to paint themselves.
For an explanation of containment hierarchies, see
Swing Components and the Containment Hierarchy,
a section in The Java Tutorial.
The JComponent class provides:
The base class for both standard and custom components
that use the Swing architecture.
A "pluggable look and feel" (L&F) that can be specified by the
programmer or (optionally) selected by the user at runtime.
The look and feel for each component is provided by a
UI delegate -- an object that descends from
ComponentUI .
See How
to Set the Look and Feel
in The Java Tutorial
for more information.
Comprehensive keystroke handling.
See the document Keyboard
Bindings in Swing,
an article in The Swing Connection,
for more information.
Support for tool tips --
short descriptions that pop up when the cursor lingers
over a component.
See How
to Use Tool Tips
in The Java Tutorial
for more information.
Support for accessibility.
JComponent contains all of the methods in the
Accessible interface,
but it doesn't actually implement the interface. That is the
responsibility of the individual classes
that extend JComponent.
An infrastructure for painting
that includes double buffering and support for borders.
For more information see Painting and
How
to Use Borders,
both of which are sections in The Java Tutorial.
JComponent and its subclasses document default values
for certain properties. For example, JTable documents the
default row height as 16. Each JComponent subclass
that has a ComponentUI will create the
ComponentUI as part of its constructor. In order
to provide a particular look and feel each
ComponentUI may set properties back on the
JComponent that created it. For example, a custom
look and feel may require JTables to have a row
height of 24. The documented defaults are the value of a property
BEFORE the ComponentUI has been installed. If you
need a specific value for a particular property you should
explicitly set it.
In release 1.4, the focus subsystem was rearchitected.
For more information, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
Warning:
Serialized objects of this 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 JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder .
JComponent, you must place the component in a containment hierarchy whose root is a top-level Swing container. Top-level Swing containers -- such asJFrame,JDialog, andJApplet-- are specialized components that provide a place for other Swing components to paint themselves. For an explanation of containment hierarchies, see Swing Components and the Containment Hierarchy, a section in The Java Tutorial.The
JComponentclass provides:- The base class for both standard and custom components
that use the Swing architecture.
- A "pluggable look and feel" (L&F) that can be specified by the
programmer or (optionally) selected by the user at runtime.
The look and feel for each component is provided by a
UI delegate -- an object that descends from
ComponentUI .
See How
to Set the Look and Feel
in The Java Tutorial
for more information.
- Comprehensive keystroke handling.
See the document Keyboard
Bindings in Swing,
an article in The Swing Connection,
for more information.
- Support for tool tips --
short descriptions that pop up when the cursor lingers
over a component.
See How
to Use Tool Tips
in The Java Tutorial
for more information.
- Support for accessibility.
- Support for component-specific properties.
With the putClientProperty(Object, Object)
and getClientProperty(Object) methods,
you can associate name-object pairs
with any object that descends from
- An infrastructure for painting
that includes double buffering and support for borders.
For more information see Painting and
How
to Use Borders,
both of which are sections in The Java Tutorial.
For more information on these subjects, see the Swing package description and The Java Tutorial section The JComponent Class.JComponentcontains all of the methods in theAccessibleinterface, but it doesn't actually implement the interface. That is the responsibility of the individual classes that extendJComponent.JComponent.JComponentand its subclasses document default values for certain properties. For example,JTabledocuments the default row height as 16. EachJComponentsubclass that has aComponentUIwill create theComponentUIas part of its constructor. In order to provide a particular look and feel eachComponentUImay set properties back on theJComponentthat created it. For example, a custom look and feel may requireJTables to have a row height of 24. The documented defaults are the value of a property BEFORE theComponentUIhas been installed. If you need a specific value for a particular property you should explicitly set it.In release 1.4, the focus subsystem was rearchitected. For more information, see How to Use the Focus Subsystem, a section in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning: Serialized objects of this 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 JavaBeansTM has been added to the
java.beanspackage. Please see XMLEncoder .