| JavaTM 2 Platform Std. Ed. v1.6.0
javax.swing
Class JComponent
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable
- Direct Known Subclasses:
- AbstractButton, BasicInternalFrameTitlePane, Box, Box.Filler, JColorChooser, JComboBox, JFileChooser, JInternalFrame, JInternalFrame.JDesktopIcon, JLabel, JLayeredPane, JList, JMenuBar, JOptionPane, JPanel, JPopupMenu, JProgressBar, JRootPane, JScrollBar, JScrollPane, JSeparator, JSlider, JSpinner, JSplitPane, JTabbedPane, JTable, JTableHeader, JTextComponent, JToolBar, JToolTip, JTree, JViewport
public abstract class JComponent - extends Container
- implements Serializable
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.
- Support for component-specific properties.
With the
putClientProperty(java.lang.Object, java.lang.Object)
and getClientProperty(java.lang.Object) methods,
you can associate name-object pairs
with any object that descends from 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.
For more information on these subjects, see the
Swing package description
and The Java Tutorial section
The JComponent Class.
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: 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.beans package.
Please see XMLEncoder.
- See Also:
KeyStroke,
Action,
setBorder(javax.swing.border.Border),
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int),
JOptionPane,
setDebugGraphicsOptions(int),
setToolTipText(java.lang.String),
setAutoscrolls(boolean)
|
Field Summary |
protected AccessibleContext |
accessibleContext
The AccessibleContext associated with this
JComponent. |
protected EventListenerList |
listenerList
A list of event listeners for this component. |
static String |
TOOL_TIP_TEXT_KEY
The comment to display when the cursor is over the component,
also known as a "value tip", "flyover help", or "flyover label". |
protected ComponentUI |
ui
The look and feel delegate for this component. |
static int |
UNDEFINED_CONDITION
Constant used by some of the APIs to mean that no condition is defined. |
static int |
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used for registerKeyboardAction that
means that the command should be invoked when the receiving
component is an ancestor of the focused component or is
itself the focused component. |
static int |
WHEN_FOCUSED
Constant used for registerKeyboardAction that
means that the command should be invoked when
the component has the focus. |
static int |
WHEN_IN_FOCUSED_WINDOW
Constant used for registerKeyboardAction that
means that the command should be invoked when
the receiving component is in the window that has the focus
or is itself the focused component. |
|
Constructor Summary |
JComponent()
Default JComponent constructor. |
|
Method Summary |
void |
addAncestorListener(AncestorListener listener)
Registers listener so that it will receive
AncestorEvents when it or any of its ancestors
move or are made visible or invisible. |
void |
addNotify()
Notifies this component that it now has a parent component. |
void |
addVetoableChangeListener(VetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list. |
void |
computeVisibleRect(Rectangle visibleRect)
Returns the Component's "visible rect rectangle" - the
intersection of the visible rectangles for this component
and all of its ancestors. |
boolean |
contains(int x,
int y)
Gives the UI delegate an opportunity to define the precise
shape of this component for the sake of mouse processing. |
JToolTip |
createToolTip()
Returns the instance of JToolTip that should be used
to display the tooltip. |
void |
disable()
Deprecated. As of JDK version 1.1,
replaced by java.awt.Component.setEnabled(boolean). |
void |
enable()
Deprecated. As of JDK version 1.1,
replaced by java.awt.Component.setEnabled(boolean). |
void |
firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
Support for reporting bound property changes for boolean properties. |
void |
firePropertyChange(String propertyName,
char oldValue,
char newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
int oldValue,
int newValue)
Support for reporting bound property changes for integer properties. |
protected void |
fireVetoableChange(String propertyName,
Object oldValue,
Object newValue)
Supports reporting constrained property changes. |
AccessibleContext |
getAccessibleContext()
Returns the AccessibleContext associated with this
JComponent. |
ActionListener |
getActionForKeyStroke(KeyStroke aKeyStroke)
Returns the object that will perform the action registered for a
given keystroke. |
ActionMap |
getActionMap()
Returns the ActionMap used to determine what
Action to fire for particular KeyStroke
binding. |
float |
getAlignmentX()
Overrides Container.getAlignmentX to return
the vertical alignment. |
float |
getAlignmentY()
Overrides Container.getAlignmentY to return
the horizontal alignment. |
AncestorListener[] |
getAncestorListeners()
Returns an array of all the ancestor listeners
registered on this component. |
boolean |
getAutoscrolls()
Gets the autoscrolls property. |
int |
getBaseline(int width,
int height)
Returns the baseline. |
Component.BaselineResizeBehavior |
getBaselineResizeBehavior()
Returns an enum indicating how the baseline of the component
changes as the size changes. |
Border |
getBorder()
Returns the border of this component or null if no
border is currently set. |
Rectangle |
getBounds(Rectangle rv)
Stores the bounds of this component into "return value"
rv and returns rv. |
Object |
getClientProperty(Object key)
Returns the value of the property with the specified key. |
protected Graphics |
getComponentGraphics(Graphics g)
Returns the graphics object used to paint this component. |
JPopupMenu |
getComponentPopupMenu()
Returns JPopupMenu that assigned for this component. |
int |
getConditionForKeyStroke(KeyStroke aKeyStroke)
Returns the condition that determines whether a registered action
occurs in response to the specified keystroke. |
int |
getDebugGraphicsOptions()
Returns the state of graphics debugging. |
static Locale |
getDefaultLocale()
Returns the default locale used to initialize each JComponent's
locale property upon creation. |
FontMetrics |
getFontMetrics(Font font)
Gets the FontMetrics for the specified Font. |
Graphics |
getGraphics()
Returns this component's graphics context, which lets you draw
on a component. |
int |
getHeight()
Returns the current height of this component. |
boolean |
getInheritsPopupMenu()
Returns true if the JPopupMenu should be inherited from the parent. |
InputMap |
getInputMap()
Returns the InputMap that is used when the
component has focus. |
InputMap |
getInputMap(int condition)
Returns the InputMap that is used during
condition. |
InputVerifier |
getInputVerifier()
Returns the input verifier for this component. |
Insets |
getInsets()
If a border has been set on this component, returns the
border's insets; otherwise calls super.getInsets. |
Insets |
getInsets(Insets insets)
Returns an Insets object containing this component's inset
values. |
|
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered
as FooListeners
upon this JComponent. |
Point |
getLocation(Point rv)
Stores the x,y origin of this component into "return value"
rv and returns rv. |
Dimension |
getMaximumSize()
If the maximum size has been set to a non-null value
just returns it. |
Dimension |
getMinimumSize()
If the minimum size has been set to a non-null value
just returns it. |
Component |
getNextFocusableComponent()
Deprecated. As of 1.4, replaced by FocusTraversalPolicy. |
Point |
getPopupLocation(MouseEvent event)
Returns the preferred location to display the popup menu in this
component's coordinate system. |
Dimension |
getPreferredSize()
If the preferredSize has been set to a
non-null value just returns it. |
KeyStroke[] |
getRegisteredKeyStrokes()
Returns the KeyStrokes that will initiate
registered actions. |
JRootPane |
getRootPane()
Returns the JRootPane ancestor for this component. |
Dimension |
getSize(Dimension rv)
Stores the width/height of this component into "return value"
rv and returns rv. |
Point |
getToolTipLocation(MouseEvent event)
Returns the tooltip location in this component's coordinate system. |
String |
getToolTipText()
Returns the tooltip string that has been set with
setToolTipText. |
String |
getToolTipText(MouseEvent event)
Returns the string to be used as the tooltip for event. |
Container |
getTopLevelAncestor()
Returns the top-level ancestor of this component (either the
containing Window or Applet),
or null if this component has not
been added to any container. |
TransferHandler |
getTransferHandler()
Gets the transferHandler property. |
String |
getUIClassID()
Returns the UIDefaults key used to
look up the name of the swing.plaf.ComponentUI
class that defines the look and feel
for this component. |
boolean |
getVerifyInputWhenFocusTarget()
Returns the value that indicates whether the input verifier for the
current focus owner will be called before this component requests
focus. |
VetoableChangeListener[] |
getVetoableChangeListeners()
Returns an array of all the vetoable change listeners
registered on this component. |
Rectangle |
getVisibleRect()
Returns the Component's "visible rectangle" - the
intersection of this component's visible rectangle,
new Rectangle(0, 0, getWidth(), getHeight()),
and all of its ancestors' visible rectangles. |
int |
getWidth()
Returns the current width of this component. |
int |
getX()
Returns the current x coordinate of the component's origin. |
int |
getY()
Returns the current y coordinate of the component's origin. |
void |
grabFocus()
Requests that this Component get the input focus, and that this
Component's top-level ancestor become the focused Window. |
boolean |
isDoubleBuffered()
Returns whether this component should use a buffer to paint. |
static boolean |
isLightweightComponent(Component c)
Returns true if this component is lightweight, that is, if it doesn't
have a native window system peer. |
boolean |
isManagingFocus()
Deprecated. As of 1.4, replaced by
Component.setFocusTraversalKeys(int, Set) and
Container.setFocusCycleRoot(boolean). |
boolean |
isOpaque()
Returns true if this component is completely opaque. |
boolean |
isOptimizedDrawingEnabled()
Returns true if this component tiles its children -- that is, if
it can guarantee that the children will not overlap. |
boolean |
isPaintingForPrint()
Returns true if the current painting operation on this
component is part of a print operation. |
boolean |
isPaintingTile()
Returns true if the component is currently painting a tile. |
boolean |
isRequestFocusEnabled()
Returns true if this JComponent should
get focus; otherwise returns false. |
boolean |
isValidateRoot()
If this method returns true, revalidate calls by
descendants of this component will cause the entire tree
beginning with this root to be validated. |
void |
paint(Graphics g)
Invoked by Swing to draw components. |
protected void |
paintBorder(Graphics g)
Paints the component's border. |
protected void |
paintChildren(Graphics g)
Paints this component's children. |
protected void |
paintComponent(Graphics g)
Calls the UI delegate's paint method, if the UI delegate
is non-null. |
void |
paintImmediately(int x,
int y,
int w,
int h)
Paints the specified region in this component and all of its
descendants that overlap the region, immediately. |
void |
paintImmediately(Rectangle r)
Paints the specified region now. |
protected String |
paramString()
Returns a string representation of this JComponent. |
void |
print(Graphics g)
Invoke this method to print the component to the specified
Graphics. |
void |
printAll(Graphics g)
Invoke this method to print the component. |
protected void |
printBorder(Graphics g)
Prints the component's border. |
protected void |
printChildren(Graphics g)
Prints this component's children. |
protected void |
printComponent(Graphics g)
This is invoked during a printing operation. |
protected void |
processComponentKeyEvent(KeyEvent e)
Processes any key events that the component itself
recognizes. |
protected boolean |
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)
Invoked to process the key bindings for ks as the result
of the KeyEvent e. |
protected void |
processKeyEvent(KeyEvent e)
Overrides processKeyEvent to process events. |
protected void |
processMouseEvent(MouseEvent e)
Processes mouse events occurring on this component by
dispatching them to any registered
MouseListener objects, refer to
Component.processMouseEvent(MouseEvent)
for a complete description of this method. |
protected void |
processMouseMotionEvent(MouseEvent e)
Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED. |
void |
putClientProperty(Object key,
Object value)
Adds an arbitrary key/value "client property" to this component. |
void |
registerKeyboardAction(ActionListener anAction,
KeyStroke aKeyStroke,
int aCondition)
This method is now obsolete, please use a combination of
getActionMap() and getInputMap() for
similiar behavior. |
void |
registerKeyboardAction(ActionListener anAction,
String aCommand,
KeyStroke aKeyStroke,
int aCondition)
This method is now obsolete, please use a combination of
getActionMap() and getInputMap() for
similiar behavior. |
void |
removeAncestorListener(AncestorListener listener)
Unregisters listener so that it will no longer receive
AncestorEvents. |
void |
removeNotify()
Notifies this component that it no longer has a parent component. |
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list. |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
Adds the specified region to the dirty region list if the component
is showing. |
void |
repaint(Rectangle r)
Adds the specified region to the dirty region list if the component
is showing. |
boolean |
requestDefaultFocus()
Deprecated. As of 1.4, replaced by
FocusTraversalPolicy.getDefaultComponent(Container).requestFocus() |
void |
requestFocus()
Requests that this Component gets the input focus. |
boolean |
requestFocus(boolean temporary)
Requests that this Component gets the input focus. |
boolean |
requestFocusInWindow()
Requests that this Component gets the input focus. |
protected boolean |
requestFocusInWindow(boolean temporary)
Requests that this Component gets the input focus. |
void |
resetKeyboardActions()
Unregisters all the bindings in the first tier InputMaps
and ActionMap. |
void |
reshape(int x,
int y,
int w,
int h)
Deprecated. As of JDK 5,
replaced by Component.setBounds(int, int, int, int).
Moves and resizes this component. |
void |
revalidate()
Supports deferred automatic layout. |
void |
scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the
JComponent's parent. |
void |
setActionMap(ActionMap am)
Sets the ActionMap to am. |
void |
setAlignmentX(float alignmentX)
Sets the the vertical alignment. |
void |
setAlignmentY(float alignmentY)
Sets the the horizontal alignment. |
void |
setAutoscrolls(boolean autoscrolls)
Sets the autoscrolls property. |
void |
setBackground(Color bg)
Sets the background color of this component. |
void |
setBorder(Border border)
Sets the border of this component. |
void |
setComponentPopupMenu(JPopupMenu popup)
Sets the JPopupMenu for this JComponent. |
void |
setDebugGraphicsOptions(int debugOptions)
Enables or disables diagnostic information about every graphics
operation performed within the component or one of its children. |
static void |
setDefaultLocale(Locale l)
Sets the default locale used to initialize each JComponent's locale
property upon creation. |
void |
setDoubleBuffered(boolean aFlag)
Sets whether this component should use a buffer to paint. |
void |
setEnabled(boolean enabled)
Sets whether or not this component is enabled. |
void |
setFocusTraversalKeys(int id,
Set<? extends AWTKeyStroke> keystrokes)
Sets the focus traversal keys for a given traversal operation for this
Component. |
void |
setFont(Font font)
Sets the font for this component. |
void |
setForeground(Color fg)
Sets the foreground color of this component. |
void |
setInheritsPopupMenu(boolean value)
Sets whether or not getComponentPopupMenu should delegate
to the parent if this component does not have a JPopupMenu
assigned to it. |
void |
setInputMap(int condition,
InputMap map)
Sets the InputMap to use under the condition
condition to
map. |
void |
setInputVerifier(InputVerifier inputVerifier)
Sets the input verifier for this component. |
void |
setMaximumSize(Dimension maximumSize)
Sets the maximum size of this component to a constant
value. |
void |
setMinimumSize(Dimension minimumSize)
Sets the minimum size of this component to a constant
value. |
void |
setNextFocusableComponent(Component aComponent)
Deprecated. As of 1.4, replaced by FocusTraversalPolicy |
void |
setOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds. |
void |
setPreferredSize(Dimension preferredSize)
Sets the preferred size of this component. |
void |
setRequestFocusEnabled(boolean requestFocusEnabled)
Provides a hint as to whether or not this JComponent
should get focus. |
void |
setToolTipText(String text)
Registers the text to display in a tool tip. |
void |
setTransferHandler(TransferHandler newHandler)
Sets the transferHandler property,
which is null if the component does
not support data transfer operations. |
protected void |
setUI(ComponentUI newUI)
Sets the look and feel delegate for this component. |
void |
setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
Sets the value to indicate whether input verifier for the
current focus owner will be called before this component requests
focus. |
void |
setVisible(boolean aFlag)
Makes the component visible or invisible. |
void |
unregisterKeyboardAction(KeyStroke aKeyStroke)
This method is now obsolete. |
void |
update(Graphics g)
Calls paint. |
void |
updateUI()
Resets the UI property to a value from the current look and feel. |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, | |