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.

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.

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 JavaBeans
TM
has been added to the java.beans package. Please see
XMLEncoder
.

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.

getPreferredSize
()
If the preferredSize has been set to a non-null value just returns it.

Dimension
PropertyChangeListener

getPreferredSize
getPropertyChangeListeners
()
If
Returns an array of all
the
preferredSize has been set
PropertyChangeListeners added
to
a non-null value just returns it.
this Component with addPropertyChangeListener().

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.
rectangle:

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
get
the input
focus.
focus, and that this Component's top-level ancestor become the focused Window.

boolean

requestFocus
(boolean temporary)
Requests
JComponent overrides requestFocus solely to make the method public so
that
this Component gets the input focus.
UI implementations can cause temporary focus changes.

boolean

requestFocusInWindow
()
Requests that this Component
gets
get
the input
focus.
focus, if this Component's top-level ancestor is already the focused Window.

protected boolean

requestFocusInWindow
(boolean temporary)
Requests
JComponent overrides requestFocusInWindow solely to make the method public so
that
this Component gets the input focus.
UI implementations can cause temporary focus changes.

accessibleContext

JComponent

public JComponent()

Default JComponent constructor. This constructor does very little initialization beyond calling the Container constructor. For example, the initial layout manager is null. It does, however, set the component's locale property to the value returned by JComponent.getDefaultLocale.

setInheritsPopupMenu
updateUI

public void setInheritsPopupMenu updateUI (boolean value) ()

Sets whether or not getComponentPopupMenu should delegate to the parent if this component does not have a JPopupMenu assigned to it.
Resets the UI property to a value from the current look and feel. JComponent subclasses must override this method like this:

public void updateUI() {
setUI((SliderUI)UIManager.getUI(this);
}

The default value for this is false, but some JComponent subclasses that are implemented as a number of JComponents may set this to true.

getInheritsPopupMenu
setUI

Returns true if the JPopupMenu should be inherited from the parent.
Sets the look and feel delegate for this component. JComponent subclasses generally override this method to narrow the argument type. For example, in JSlider:

public void setUI(SliderUI newUI) {
super.setUI(newUI);
}

Additionally JComponent subclasses must provide a getUI method that returns the correct type. For example:

setComponentPopupMenu
getUIClassID

Sets the JPopupMenu for this JComponent. The UI is responsible for registering bindings and adding the necessary listeners such that the JPopupMenu will be shown at the appropriate time. When the JPopupMenu is shown depends upon the look and feel: some may show it on a mouse event, some may enable a key binding.
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. Most applications will never need to call this method. Subclasses of JComponent that support pluggable look and feel should override this method to return a UIDefaults key that maps to the ComponentUI subclass that defines their look and feel.

If popup is null, and getInheritsPopupMenu returns true, then getComponentPopupMenu will be delegated to the parent. This provides for a way to make all child components inherit the popupmenu of the parent.

This is a bound property.

Parameters:
Returns:

popup - - the popup that will be assigned to this component may be null
the UIDefaults key for a ComponentUI subclass

getComponentPopupMenu
getComponentGraphics

Returns JPopupMenu that assigned for this component. If this component does not have a JPopupMenu assigned to it and getInheritsPopupMenu is true, this will return getParent().getComponentPopupMenu() (assuming the parent is valid.)
Returns the graphics object used to paint this component. If DebugGraphics is turned on we create a new DebugGraphics object if necessary. Otherwise we just configure the specified graphics object's foreground and font.

Returns:
Parameters:

JPopupMenu assigned for this component or null if no popup assigned
g - the original Graphics object

updateUI
paintComponent

Resets the UI property to a value from the current look and feel. JComponent subclasses must override this method like this:

public void updateUI() {
setUI((SliderUI)UIManager.getUI(this);
}

Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate).

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts.

setUI
paintChildren

Sets the look and feel delegate for this component. JComponent subclasses generally override this method to narrow the argument type. For example, in JSlider:

public void setUI(SliderUI newUI) {
super.setUI(newUI);
}

Paints this component's children. If shouldUseBuffer is true, no component ancestor has a buffer and the component children can use a buffer if they have one. Otherwise, one ancestor has a buffer currently in use and children should not use a buffer to paint.

Additionally JComponent subclasses must provide a getUI method that returns the correct type. For example:

public SliderUI getUI() {
return (SliderUI)ui;
}

Parameters:

newUI - the new UI delegate
g - the Graphics context in which to paint

getUIClassID
paintBorder

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. Most applications will never need to call this method. Subclasses of JComponent that support pluggable look and feel should override this method to return a UIDefaults key that maps to the ComponentUI subclass that defines their look and feel.
Paints the component's border.

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it.

Returns:
Parameters:

the UIDefaults key for a ComponentUI subclass
g - the Graphics context in which to paint

getComponentGraphics
update

Returns the graphics object used to paint this component. If DebugGraphics is turned on we create a new DebugGraphics object if necessary. Otherwise we just configure the specified graphics object's foreground and font.
Calls paint. Doesn't clear the background but see ComponentUI.update, which is called by paintComponent.

paintComponent
paint

Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate).
Invoked by Swing to draw components. Applications should not invoke paint directly, but should instead use the repaint method to schedule the component for redrawing.

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts.
This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent.

The passed in Graphics object might have a transform other than the identify transform installed on it. In this case, you might get unexpected results if you cumulatively apply another transform.

paintChildren
printAll

Paints this component's children. If shouldUseBuffer is true, no component ancestor has a buffer and the component children can use a buffer if they have one. Otherwise, one ancestor has a buffer currently in use and children should not use a buffer to paint.
Invoke this method to print the component. This method invokes print on the component.

paintBorder
print

Paints the component's border.
Invoke this method to print the component. This method will result in invocations to printComponent, printBorder and printChildren. It is not recommended that you override this method, instead override one of the previously mentioned methods. This method sets the component's state such that the double buffer will not be used, eg painting will be done directly on the passed in Graphics.

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it.

update
printComponent

Calls paint. Doesn't clear the background but see ComponentUI.update, which is called by paintComponent.
This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing.

paint
printChildren

Invoked by Swing to draw components. Applications should not invoke paint directly, but should instead use the repaint method to schedule the component for redrawing.
Prints this component's children. This is implemented to invoke paintChildren on the component. Override this if you wish to print the children differently than painting.

This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. They're called in the order listed to ensure that children appear on top of component itself. Generally speaking, the component and its children should not paint in the insets area allocated to the border. Subclasses can just override this method, as always. A subclass that just wants to specialize the UI (look and feel) delegate's paint method should just override paintComponent.

printAll
printBorder

Invoke this method to print the component. This method invokes print on the component.
Prints the component's border. This is implemented to invoke paintBorder on the component. Override this if you wish to print the border differently that it is painted.

print
isPaintingTile

Invoke this method to print the component. This method will result in invocations to printComponent, printBorder and printChildren. It is not recommended that you override this method, instead override one of the previously mentioned methods. This method sets the component's state such that the double buffer will not be used, eg painting will be done directly on the passed in Graphics.
Returns true if the component is currently painting a tile. If this method returns true, paint will be called again for another tile. This method returns false if you are not painting a tile or if the last tile is painted. Use this method to keep some state you might need between tiles.

printComponent
isManagingFocus

This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing.
Deprecated.
As of 1.4, replaced by Component.setFocusTraversalKeys(int, Set) and Container.setFocusCycleRoot(boolean).

Changes this JComponent's focus traversal keys to CTRL+TAB and CTRL+SHIFT+TAB. Also prevents SortingFocusTraversalPolicy from considering descendants of this JComponent when computing a focus traversal cycle.

printChildren
setNextFocusableComponent

Prints this component's children. This is implemented to invoke paintChildren on the component. Override this if you wish to print the children differently than painting.
Deprecated.
As of 1.4, replaced by FocusTraversalPolicy

Overrides the default FocusTraversalPolicy for this JComponent's focus traversal cycle by unconditionally setting the specified Component as the next Component in the cycle, and this JComponent as the specified Component's previous Component in the cycle.

Parameters:

g - the Graphics context in which to paint
aComponent - the Component that should follow this JComponent in the focus traversal cycle

printBorder
getNextFocusableComponent

Prints the component's border. This is implemented to invoke paintBorder on the component. Override this if you wish to print the border differently that it is painted.
Deprecated.
As of 1.4, replaced by FocusTraversalPolicy.

Returns the Component set by a prior call to setNextFocusableComponent(Component) on this JComponent.

Parameters:
Returns:

g - the Graphics context in which to paint
the Component that will follow this JComponent in the focus traversal cycle, or null if none has been explicitly specified

isPaintingTile
setRequestFocusEnabled

Returns true if the component is currently painting a tile. If this method returns true, paint will be called again for another tile. This method returns false if you are not painting a tile or if the last tile is painted. Use this method to keep some state you might need between tiles.
Provides a hint as to whether or not this JComponent should get focus. This is only a hint, and it is up to consumers that are requesting focus to honor this property. This is typically honored for mouse operations, but not keyboard operations. For example, look and feels could verify this property is true before requesting focus during a mouse operation. This would often times be used if you did not want a mouse press on a JComponent to steal focus, but did want the JComponent to be traversable via the keyboard. If you do not want this JComponent focusable at all, use the setFocusable method instead.

Returns:
Parameters:

true if the component is currently painting a tile, false otherwise
requestFocusEnabled - Indicates if you want this JComponent to be focusable or not

Changes this JComponent's focus traversal keys to CTRL+TAB and CTRL+SHIFT+TAB. Also prevents SortingFocusTraversalPolicy from considering descendants of this JComponent when computing a focus traversal cycle.

setNextFocusableComponent
requestFocus

Deprecated.
Description copied from class:
Component
As of 1.4, replaced by FocusTraversalPolicy

Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. This component must be displayable, visible, and focusable for the request to be granted. Every effort will be made to honor the request; however, in some cases it may be impossible to do so. Developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event. If this request is denied because this Component's top-level Window cannot become the focused Window, the request will be remembered and will be granted when the Window is later focused by the user.

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.
This method cannot be used to set the focus owner to no Component at all. Use KeyboardFocusManager.clearGlobalFocusOwner() instead.

Overrides the default FocusTraversalPolicy for this JComponent's focus traversal cycle by unconditionally setting the specified Component as the next Component in the cycle, and this JComponent as the specified Component's previous Component in the cycle.
Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible.

getNextFocusableComponent
requestFocus

Deprecated.
As of 1.4, replaced by FocusTraversalPolicy.
JComponent overrides requestFocus solely to make the method public so that UI implementations can cause temporary focus changes. This method is not meant for general use, instead developers are urged to call the noarg requestFocus or requestFocusInWindow methods. If the JComponent has an InputVerifierassociated with it, the InputVerifier will be messaged.

the Component that will follow this JComponent in the focus traversal cycle, or null if none has been explicitly specified
false if the focus change request is guaranteed to fail; true if it is likely to succeed

setRequestFocusEnabled
requestFocusInWindow

Provides a hint as to whether or not this JComponent should get focus. This is only a hint, and it is up to consumers that are requesting focus to honor this property. This is typically honored for mouse operations, but not keyboard operations. For example, look and feels could verify this property is true before requesting focus during a mouse operation. This would often times be used if you did not want a mouse press on a JComponent to steal focus, but did want the JComponent to be traversable via the keyboard. If you do not want this JComponent focusable at all, use the setFocusable method instead.
Description copied from class:
Component

Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. This component must be displayable, visible, and focusable for the request to be granted. Every effort will be made to honor the request; however, in some cases it may be impossible to do so. Developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event.

Please see
How to Use the Focus Subsystem
, a section in The Java Tutorial, for more information.
This method returns a boolean value. If false is returned, the request is
guaranteed to fail
. If true is returned, the request will succeed
unless
it is vetoed, or an extraordinary event, such as disposal of the Component's peer, occurs before the request can be granted by the native windowing system. Again, while a return value of true indicates that the request is likely to succeed, developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event.

This method cannot be used to set the focus owner to no Component at all. Use KeyboardFocusManager.clearGlobalFocusOwner() instead.

The focus behavior of this method can be implemented uniformly across platforms, and thus developers are strongly encouraged to use this method over requestFocus when possible. Code which relies on requestFocus may exhibit different focus behavior on different platforms.

isRequestFocusEnabled
requestFocusInWindow

Returns true if this JComponent should get focus; otherwise returns false.
JComponent overrides requestFocusInWindow solely to make the method public so that UI implementations can cause temporary focus changes. This method is not meant for general use, instead developers are urged to call the noarg requestFocus or requestFocusInWindow methods. If the JComponent has an InputVerifierassociated with it, the InputVerifier will be messaged.

requestFocus
grabFocus

public void requestFocus grabFocus ()

Requests that this Component gets the input focus. Refer to
Component.requestFocus()
for a complete description of this method.
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. This component must be displayable, visible, and focusable for the request to be granted.

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of
requestFocusInWindow()
. If you would like more information on focus, see

requestFocus
setVerifyInputWhenFocusTarget

Requests that this Component gets the input focus. Refer to
Component.requestFocus(boolean)
for a complete description of this method.
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. The default is true. Set to false on components such as a Cancel button or a scrollbar, which should activate even if the input in the current focus owner is not "passed" by the input verifier for that component.

requestFocusInWindow
getVerifyInputWhenFocusTarget

public boolean requestFocusInWindow getVerifyInputWhenFocusTarget ()

Requests that this Component gets the input focus. Refer to
Component.requestFocusInWindow()
for a complete description of this method.
Returns the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus.

requestFocusInWindow
setPreferredSize

Requests that this Component gets the input focus. Refer to
Component.requestFocusInWindow(boolean)
for a complete description of this method.
Sets the preferred size of this component. If preferredSize is null, the UI will be asked for the preferred size.

grabFocus
getPreferredSize

public void
public DimensiongrabFocus getPreferredSize ()

Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. This component must be displayable, visible, and focusable for the request to be granted.
If the preferredSize has been set to a non-null value just returns it. If the UI delegate's getPreferredSize method returns a non null value then return that; otherwise defer to the component's layout manager.

This method is intended for use by focus implementations. Client code should not use this method; instead, it should use requestFocusInWindow().

setVerifyInputWhenFocusTarget
setMaximumSize

Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. The default is true. Set to false on components such as a Cancel button or a scrollbar, which should activate even if the input in the current focus owner is not "passed" by the input verifier for that component.
Sets the maximum size of this component to a constant value. Subsequent calls to getMaximumSize will always return this value; the component's UI will not be asked to compute it. Setting the maximum size to null restores the default behavior.

getVerifyInputWhenFocusTarget
getMaximumSize

public boolean
public DimensiongetVerifyInputWhenFocusTarget getMaximumSize ()

Returns the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus.
If the maximum size has been set to a non-null value just returns it. If the UI delegate's getMaximumSize method returns a non-null value then return that; otherwise defer to the component's layout manager.

getFontMetrics
setMinimumSize

Gets the FontMetrics for the specified Font.
Sets the minimum size of this component to a constant value. Subsequent calls to getMinimumSize will always return this value; the component's UI will not be asked to compute it. Setting the minimum size to null restores the default behavior.

setPreferredSize
getMinimumSize

Sets the preferred size of this component. If preferredSize is null, the UI will be asked for the preferred size.
If the minimum size has been set to a non-null value just returns it. If the UI delegate's getMinimumSize method returns a non-null value then return that; otherwise defer to the component's layout manager.

getPreferredSize
isMinimumSizeSet

public Dimension
public boolean getPreferredSize isMinimumSizeSet ()

If the preferredSize has been set to a non-null value just returns it. If the UI delegate's getPreferredSize method returns a non null value then return that; otherwise defer to the component's layout manager.
Returns true if the minimum size has been set to a non-null value otherwise returns false.

setMaximumSize
isPreferredSizeSet

Sets the maximum size of this component to a constant value. Subsequent calls to getMaximumSize will always return this value; the component's UI will not be asked to compute it. Setting the maximum size to null restores the default behavior.
Returns true if the preferred size has been set to a non-null value otherwise returns false.

getMaximumSize
isMaximumSizeSet

public Dimension
public boolean getMaximumSize isMaximumSizeSet ()

If the maximum size has been set to a non-null value just returns it. If the UI delegate's getMaximumSize method returns a non-null value then return that; otherwise defer to the component's layout manager.
Returns true if the maximum size has been set to a non-null value otherwise returns false.

setMinimumSize
contains

Sets the minimum size of this component to a constant value. Subsequent calls to getMinimumSize will always return this value; the component's UI will not be asked to compute it. Setting the minimum size to null restores the default behavior.
Gives the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing.

getMinimumSize
setBorder

If the minimum size has been set to a non-null value just returns it. If the UI delegate's getMinimumSize method returns a non-null value then return that; otherwise defer to the component's layout manager.
Sets the border of this component. The Border object is responsible for defining the insets for the component (overriding any insets set directly on the component) and for optionally rendering any border decorations within the bounds of those insets. Borders should be used (rather than insets) for creating both decorative and non-decorative (such as margins and padding) regions for a swing component. Compound borders can be used to nest multiple borders within a single component.

setBorder
getInsets

Sets the border of this component. The Border object is responsible for defining the insets for the component (overriding any insets set directly on the component) and for optionally rendering any border decorations within the bounds of those insets. Borders should be used (rather than insets) for creating both decorative and non-decorative (such as margins and padding) regions for a swing component. Compound borders can be used to nest multiple borders within a single component.
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Although technically you can set the border on any object that inherits from JComponent
, the look and feel implementation of many standard Swing components doesn't work well with user-set borders. In general, when you want to set a border on a standard Swing component other than JPanel or JLabel, we recommend that you put the component in a JPanel and set the border on the JPanel.

getBorder
getInsets

Returns the border of this component or null if no border is currently set.
Returns an Insets object containing this component's inset values. The passed-in Insets object will be reused if possible. Calling methods cannot assume that the same object will be returned, however. All existing values within this object are overwritten. If insets is null, this will allocate a new one.

getInsets
setAlignmentY

Returns an Insets object containing this component's inset values. The passed-in Insets object will be reused if possible. Calling methods cannot assume that the same object will be returned, however. All existing values within this object are overwritten. If insets is null, this will allocate a new one.
Sets the the horizontal alignment.

Parameters:

insets - the Insets object, which can be reused
alignmentY - the new horizontal alignment

setInputVerifier
getGraphics

Sets the input verifier for this component.
Returns this component's graphics context, which lets you draw on a component. Use this method get a Graphics object and then invoke operations on that object to draw on the component.

getGraphics
getDebugGraphicsOptions

Returns this component's graphics context, which lets you draw on a component. Use this method get a Graphics object and then invoke operations on that object to draw on the component.
Returns the state of graphics debugging.

setDebugGraphicsOptions
registerKeyboardAction

Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similiar behavior. For example, to bind the KeyStroke aKeyStroke to the Action anAction now use:

The above assumes you want the binding to be applicable for WHEN_FOCUSED. To register bindings for other focus states use the getInputMap method that takes an integer.

Register a new keyboard action. anAction will be invoked if a key event matching aKeyStroke occurs and aCondition is verified. The KeyStroke object defines a particular combination of a keyboard key and one or more modifiers (alt, shift, ctrl, meta).

The aCommand will be set in the delivered event if specified.

The aCondition can be one of:

WHEN_FOCUSED

The action will be invoked only when the keystroke occurs while the component has the focus.

WHEN_IN_FOCUSED_WINDOW

The action will be invoked when the keystroke occurs while the component has the focus or if the component is in the window that has the focus. Note that the component need not be an immediate descendent of the window -- it can be anywhere in the window's containment hierarchy. In other words, whenever any component in the window has the focus, the action registered with this component is invoked.

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

The action will be invoked when the keystroke occurs while the component has the focus or if the component is an ancestor of the component that has the focus.

The combination of keystrokes and conditions lets you define high level (semantic) action events for a specified keystroke+modifier combination (using the KeyStroke class) and direct to a parent or child of a component that has the focus, or to the component itself. In other words, in any hierarchical structure of components, an arbitrary key-combination can be immediately directed to the appropriate component in the hierarchy, and cause a specific method to be invoked (usually by way of adapter objects).

If an action has already been registered for the receiving container, with the same charCode and the same modifiers, anAction will replace the action.

Parameters:

debugOptions - determines how the component should display the information; one of the following options:

DebugGraphics.LOG_OPTION - causes a text message to be printed.

DebugGraphics.FLASH_OPTION - causes the drawing to flash several times.

DebugGraphics.BUFFERED_OPTION - creates an ExternalWindow that displays the operations performed on the View's offscreen buffer.

DebugGraphics.NONE_OPTION disables debugging.

A value of 0 causes no changes to the debugging options.

debugOptions is bitwise OR'd into the current value
anAction - the Action to be registered

The above assumes you want the binding to be applicable for WHEN_FOCUSED. To register bindings for other focus states use the getInputMap method that takes an integer.
This method is now obsolete. To unregister an existing binding you can either remove the binding from the ActionMap/InputMap, or place a dummy binding the InputMap. Removing the binding from the InputMap allows bindings in parent InputMaps to be active, whereas putting a dummy binding in the InputMap effectively disables the binding from ever happening.

Register a new keyboard action. anAction will be invoked if a key event matching aKeyStroke occurs and aCondition is verified. The KeyStroke object defines a particular combination of a keyboard key and one or more modifiers (alt, shift, ctrl, meta).
Unregisters a keyboard action. This will remove the binding from the ActionMap (if it exists) as well as the InputMaps.

The aCommand will be set in the delivered event if specified.

The aCondition can be one of:

WHEN_FOCUSED

The action will be invoked only when the keystroke occurs while the component has the focus.

WHEN_IN_FOCUSED_WINDOW

The action will be invoked when the keystroke occurs while the component has the focus or if the component is in the window that has the focus. Note that the component need not be an immediate descendent of the window -- it can be anywhere in the window's containment hierarchy. In other words, whenever any component in the window has the focus, the action registered with this component is invoked.

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

The action will be invoked when the keystroke occurs while the component has the focus or if the component is an ancestor of the component that has the focus.

The combination of keystrokes and conditions lets you define high level (semantic) action events for a specified keystroke+modifier combination (using the KeyStroke class) and direct to a parent or child of a component that has the focus, or to the component itself. In other words, in any hierarchical structure of components, an arbitrary key-combination can be immediately directed to the appropriate component in the hierarchy, and cause a specific method to be invoked (usually by way of adapter objects).

If an action has already been registered for the receiving container, with the same charCode and the same modifiers, anAction will replace the action.

unregisterKeyboardAction
getConditionForKeyStroke

This method is now obsolete. To unregister an existing binding you can either remove the binding from the ActionMap/InputMap, or place a dummy binding the InputMap. Removing the binding from the InputMap allows bindings in parent InputMaps to be active, whereas putting a dummy binding in the InputMap effectively disables the binding from ever happening.
Returns the condition that determines whether a registered action occurs in response to the specified keystroke.

Unregisters a keyboard action. This will remove the binding from the ActionMap (if it exists) as well as the InputMaps.
For Java 2 platform v1.3, a KeyStroke can be associated with more than one condition. For example, 'a' could be bound for the two conditions WHEN_FOCUSED and WHEN_IN_FOCUSED_WINDOW condition.

getConditionForKeyStroke
resetKeyboardActions

Returns the condition that determines whether a registered action occurs in response to the specified keystroke.
Unregisters all the bindings in the first tier InputMaps and ActionMap. This has the effect of removing any local bindings, and allowing the bindings defined in parent InputMap/ActionMaps (the UI is usually defined in the second tier) to persist.

For Java 2 platform v1.3, a KeyStroke can be associated with more than one condition. For example, 'a' could be bound for the two conditions WHEN_FOCUSED and WHEN_IN_FOCUSED_WINDOW condition.

Returns:

the action-keystroke condition

getActionForKeyStroke
setInputMap

Returns the object that will perform the action registered for a given keystroke.
Sets the InputMap to use under the condition condition to map. A null value implies you do not want any bindings to be used, even from the UI. This will not reinstall the UI InputMap (if there was one). condition has one of the following values:

WHEN_IN_FOCUSED_WINDOW

WHEN_FOCUSED

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

If condition is WHEN_IN_FOCUSED_WINDOW and map is not a ComponentInputMap, an IllegalArgumentException will be thrown. Similarly, if condition is not one of the values listed, an IllegalArgumentException will be thrown.

Returns:
Parameters:

the ActionListener object invoked when the keystroke occurs
condition - one of the values listed above

map - the InputMap to use for the given condition

Throws:

IllegalArgumentException
- if condition is WHEN_IN_FOCUSED_WINDOW and map is not an instance of ComponentInputMap; or if condition is not one of the legal values specified above

Since:

1.3

resetKeyboardActions
getInputMap

public void
public final InputMapresetKeyboardActions getInputMap () (int condition)

Unregisters all the bindings in the first tier InputMaps and ActionMap. This has the effect of removing any local bindings, and allowing the bindings defined in parent InputMap/ActionMaps (the UI is usually defined in the second tier) to persist.
Returns the InputMap that is used during condition.

setInputMap
getInputMap

Sets the InputMap to use under the condition condition to map. A null value implies you do not want any bindings to be used, even from the UI. This will not reinstall the UI InputMap (if there was one). condition has one of the following values:

WHEN_IN_FOCUSED_WINDOW

WHEN_FOCUSED

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

If condition is WHEN_IN_FOCUSED_WINDOW and map is not a ComponentInputMap, an IllegalArgumentException will be thrown. Similarly, if condition is not one of the values listed, an IllegalArgumentException will be thrown.
Returns the InputMap that is used when the component has focus. This is convenience method for getInputMap(WHEN_FOCUSED).

Parameters:
Returns:

condition - one of the values listed above

map - the InputMap to use for the given condition
the InputMap used when the component has focus

Throws:

IllegalArgumentException
- if condition is WHEN_IN_FOCUSED_WINDOW and map is not an instance of ComponentInputMap; or if condition is not one of the legal values specified above

Since:

1.3
JDK1.3

getInputMap
setActionMap

Returns the InputMap that is used during condition.
Sets the ActionMap to am. This does not set the parent of the am to be the ActionMap from the UI (if there was one), it is up to the caller to have done this.

Parameters:

condition - one of WHEN_IN_FOCUSED_WINDOW, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
am - the new ActionMap

Returns:

the InputMap for the specified condition

Since:

1.3

getInputMap
getActionMap

public final InputMapActionMapgetInputMap getActionMap ()

Returns the InputMap that is used when the component has focus. This is convenience method for getInputMap(WHEN_FOCUSED).
Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding. The returned ActionMap, unless otherwise set, will have the ActionMap from the UI set as the parent.

Returns:

the InputMap used when the component has focus
the ActionMap containing the key/action bindings

Since:

JDK1.3
1.3

setActionMap
requestDefaultFocus

Sets the ActionMap to am. This does not set the parent of the am to be the ActionMap from the UI (if there was one), it is up to the caller to have done this.
Deprecated.
As of 1.4, replaced by FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()

Requests focus on this JComponent's FocusTraversalPolicy's default Component. If this JComponent is a focus cycle root, then its FocusTraversalPolicy is used. Otherwise, the FocusTraversalPolicy of this JComponent's focus-cycle-root ancestor is used.

getActionMap
setVisible

public final ActionMap
public void getActionMap setVisible () (boolean aFlag)

Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding. The returned ActionMap, unless otherwise set, will have the ActionMap from the UI set as the parent.
Makes the component visible or invisible. Overrides Component.setVisible.

requestDefaultFocus
setEnabled

Deprecated.
As of 1.4, replaced by FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()
Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input.

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.
Note: Disabling a component does not disable it's children.

Requests focus on this JComponent's FocusTraversalPolicy's default Component. If this JComponent is a focus cycle root, then its FocusTraversalPolicy is used. Otherwise, the FocusTraversalPolicy of this JComponent's focus-cycle-root ancestor is used.
Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.

setEnabled
setBackground

Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input.
Sets the background color of this component.

Note: Disabling a component does not disable it's children.

Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.

setBackground
getDefaultLocale

Sets the background color of this component.
Returns the default locale used to initialize each JComponent's locale property upon creation. The default locale has "AppContext" scope so that applets (and potentially multiple lightweight applications running in a single VM) can have their own setting. An applet can safely alter its default locale because it will have no affect on other applets (or the browser).

setFont
setDefaultLocale

Sets the font for this component.
Sets the default locale used to initialize each JComponent's locale property upon creation. The initial value is the VM's default locale. The default locale has "AppContext" scope so that applets (and potentially multiple lightweight applications running in a single VM) can have their own setting. An applet can safely alter its default locale because it will have no affect on other applets (or the browser).

getDefaultLocale
processComponentKeyEvent

Returns the default locale used to initialize each JComponent's locale property upon creation. The default locale has "AppContext" scope so that applets (and potentially multiple lightweight applications running in a single VM) can have their own setting. An applet can safely alter its default locale because it will have no affect on other applets (or the browser).
Processes any key events that the component itself recognizes. This is called after the focus manager and any interested listeners have been given a chance to steal away the event. This method is called only if the event has not yet been consumed. This method is called prior to the keyboard UI logic.

This method is implemented to do nothing. Subclasses would normally override this method if they process some key events themselves. If the event is processed, it should be consumed.

setDefaultLocale
processKeyEvent

Sets the default locale used to initialize each JComponent's locale property upon creation. The initial value is the VM's default locale. The default locale has "AppContext" scope so that applets (and potentially multiple lightweight applications running in a single VM) can have their own setting. An applet can safely alter its default locale because it will have no affect on other applets (or the browser).
Overrides processKeyEvent to process events.

processComponentKeyEvent
processKeyBinding

Processes any key events that the component itself recognizes. This is called after the focus manager and any interested listeners have been given a chance to steal away the event. This method is called only if the event has not yet been consumed. This method is called prior to the keyboard UI logic.
Invoked to process the key bindings for ks as the result of the KeyEvent e. This obtains the appropriate InputMap, gets the binding, gets the action from the ActionMap, and then (if the action is found and the component is enabled) invokes notifyAction to notify the action.

This method is implemented to do nothing. Subclasses would normally override this method if they process some key events themselves. If the event is processed, it should be consumed.

processKeyBinding
getToolTipText

Invoked to process the key bindings for ks as the result of the KeyEvent e. This obtains the appropriate InputMap, gets the binding, gets the action from the ActionMap, and then (if the action is found and the component is enabled) invokes notifyAction to notify the action.
Returns the tooltip string that has been set with setToolTipText.

Parameters:

ks - the KeyStroke queried

e - the KeyEvent

condition - one of the following values:

JComponent.WHEN_FOCUSED

JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

JComponent.WHEN_IN_FOCUSED_WINDOW

pressed - true if the key is pressed

Returns:

true if there was a binding to an action, and the action was enabled
the text of the tool tip

setToolTipText
getToolTipText

Registers the text to display in a tool tip. The text displays when the cursor lingers over the component.
Returns the string to be used as the tooltip for
event
. By default this returns any string set using setToolTipText. If a component provides more extensive API to support differing tooltips at different locations, this method should be overridden.

getToolTipText
getToolTipLocation

Returns the tooltip string that has been set with setToolTipText.
Returns the tooltip location in this component's coordinate system. If null is returned, Swing will choose a location. The default implementation returns null.

Returns:
Parameters:

the text of the tool tip
event - the MouseEvent that caused the ToolTipManager to show the tooltip

getToolTipText
createToolTip

Returns the string to be used as the tooltip for
event
. By default this returns any string set using setToolTipText. If a component provides more extensive API to support differing tooltips at different locations, this method should be overridden.
Returns the instance of JToolTip that should be used to display the tooltip. Components typically would not override this method, but it can be used to cause different tooltips to be displayed differently.

Returns:

the JToolTip used to display this toolTip

getToolTipLocation
scrollRectToVisible

public Point
public void getToolTipLocation scrollRectToVisible ( MouseEventRectangle event) aRect)

Returns the tooltip location in this component's coordinate system. If null is returned, Swing will choose a location. The default implementation returns null.
Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.

Parameters:

event - the MouseEvent that caused the ToolTipManager to show the tooltip
aRect - the visible Rectangle

getPopupLocation
setAutoscrolls

Returns the preferred location to display the popup menu in this component's coordinate system. It is up to the look and feel to honor this propery, some may choose to ignore it. If null is truend the look and feel will choose a suitable location.
Sets the autoscrolls property. If true mouse dragged events will be synthetically generated when the mouse is dragged outside of the component's bounds and mouse motion has paused (while the button continues to be held down). The synthetic events make it appear that the drag gesture has resumed in the direction established when the component's boundary was crossed. Components that support autoscrolling must handle mouseDragged events by calling scrollRectToVisible with a rectangle that contains the mouse event's location. All of the Swing components that support item selection and are typically displayed in a JScrollPane (JTable, JList, JTree, JTextArea, and JEditorPane) already handle mouse dragged events in this way. To enable autoscrolling in any other component, add a mouse motion listener that calls scrollRectToVisible. For example, given a JPanel, myPanel:

event - the MouseEvent that triggered the popup to be shown, or null if popup was is not being shown as the result of a mouse event
autoscrolls - if true, synthetic mouse dragged events are generated when the mouse is dragged outside of a component's bounds and the mouse button continues to be held down; otherwise false

createToolTip
getAutoscrolls

Returns the instance of JToolTip that should be used to display the tooltip. Components typically would not override this method, but it can be used to cause different tooltips to be displayed differently.
Gets the autoscrolls property.

Returns:

the JToolTip used to display this toolTip
the value of the autoscrolls property

scrollRectToVisible
setTransferHandler

Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.
Sets the transferHandler property, which is null if the component does not support data transfer operations.

If newHandler is not null, and the system property suppressSwingDropSupport is not true, this will install a DropTarget on the JComponent. The default for the system property is false, so that a DropTarget will be added.

Parameters:

aRect - the visible Rectangle
newHandler - mechanism for transfer of data to and from the component

setAutoscrolls
getTransferHandler

Sets the autoscrolls property. If true mouse dragged events will be synthetically generated when the mouse is dragged outside of the component's bounds and mouse motion has paused (while the button continues to be held down). The synthetic events make it appear that the drag gesture has resumed in the direction established when the component's boundary was crossed. Components that support autoscrolling must handle mouseDragged events by calling scrollRectToVisible with a rectangle that contains the mouse event's location. All of the Swing components that support item selection and are typically displayed in a JScrollPane (JTable, JList, JTree, JTextArea, and JEditorPane) already handle mouse dragged events in this way. To enable autoscrolling in any other component, add a mouse motion listener that calls scrollRectToVisible. For example, given a JPanel, myPanel:

The default value of the autoScrolls property is false.
Gets the transferHandler property.

Parameters:
Returns:

autoscrolls - if true, synthetic mouse dragged events are generated when the mouse is dragged outside of a component's bounds and the mouse button continues to be held down; otherwise false
the value of the transferHandler property

setTransferHandler
enable

Sets the transferHandler property, which is null if the component does not support data transfer operations.
Deprecated.
As of JDK version 1.1, replaced by java.awt.Component.setEnable(boolean).

If newHandler is not null, and the system property suppressSwingDropSupport is not true, this will install a DropTarget on the JComponent. The default for the system property is false, so that a DropTarget will be added.

processMouseEvent
getAccessibleContext

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.
Returns the AccessibleContext associated with this JComponent. The method implemented by this base class returns null. Classes that extend JComponent should implement this method to return the AccessibleContext associated with the subclass.

enable
putClientProperty

The get/putClientProperty methods provide access to a small per-instance hashtable. Callers can use get/putClientProperty to annotate components that were created by another module. For example, a layout manager might store per child constraints this way. For example:

componentA.putClientProperty("to the left of", componentB);

If value is null this method will remove the property. Changes to client properties are reported with PropertyChange events. The name of the property (for the sake of PropertyChange events) is key.toString().

The clientProperty dictionary is not intended to support large scale extensions to JComponent nor should be it considered an alternative to subclassing when designing a new component.

Deprecated.
Parameters:
As of JDK version 1.1, replaced by java.awt.Component.setEnabled(boolean).

key - the new client property key

value - the new client property value; if null this method will remove the property

getAccessibleContext
reshape

Returns the AccessibleContext associated with this JComponent. The method implemented by this base class returns null. Classes that extend JComponent should implement this method to return the AccessibleContext associated with the subclass.
Moves and resizes this component.

getClientProperty
getBounds

Returns the value of the property with the specified key. Only properties added with putClientProperty will return a non-null value.
Stores the bounds of this component into "return value" rv and returns rv. If rv is null a new Rectangle is allocated. This version of getBounds is useful if the caller wants to avoid allocating a new Rectangle object on the heap.

putClientProperty
getSize

Adds an arbitrary key/value "client property" to this component.
Stores the width/height of this component into "return value" rv and returns rv. If rv is null a new Dimension object is allocated. This version of getSize is useful if the caller wants to avoid allocating a new Dimension object on the heap.

The get/putClientProperty methods provide access to a small per-instance hashtable. Callers can use get/putClientProperty to annotate components that were created by another module. For example, a layout manager might store per child constraints this way. For example:

componentA.putClientProperty("to the left of", componentB);

If value is null this method will remove the property. Changes to client properties are reported with PropertyChange events. The name of the property (for the sake of PropertyChange events) is key.toString().

The clientProperty dictionary is not intended to support large scale extensions to JComponent nor should be it considered an alternative to subclassing when designing a new component.

setFocusTraversalKeys
getLocation

Sets the focus traversal keys for a given traversal operation for this Component. Refer to
Component.setFocusTraversalKeys(int, java.util.Set)
for a complete description of this method.
Stores the x,y origin of this component into "return value" rv and returns rv. If rv is null a new Point is allocated. This version of getLocation is useful if the caller wants to avoid allocating a new Point object on the heap.

id - one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS

keystrokes - the Set of AWTKeyStroke for the specified operation
rv - the return value, modified to the component's location

Throws:
Returns:

IllegalArgumentException
- if id is not one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes contains null, or if any Object in keystrokes is not an AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, or if any keystroke already maps to another focus traversal operation for this Component

isLightweightComponent
getX

Returns true if this component is lightweight, that is, if it doesn't have a native window system peer.
Returns the current x coordinate of the component's origin. This method is preferable to writing component.getBounds().x, or component.getLocation().x because it doesn't cause any heap allocations.

true if this component is lightweight
the current x coordinate of the component's origin

reshape
getY

public void int reshape getY (int x,
int y,
int w,
int h) ()

Deprecated.
As of JDK version 1.5, replaced by Component.setBounds(int, int, int, int).
Returns the current y coordinate of the component's origin. This method is preferable to writing component.getBounds().y, or component.getLocation().y because it doesn't cause any heap allocations.

getBounds
getWidth

Stores the bounds of this component into "return value" rv and returns rv. If rv is null a new Rectangle is allocated. This version of getBounds is useful if the caller wants to avoid allocating a new Rectangle object on the heap.
Returns the current width of this component. This method is preferable to writing component.getBounds().width, or component.getSize().width because it doesn't cause any heap allocations.

rv; if rv is null return a newly created Rectangle with this component's bounds
the current width of this component

getSize
getHeight

public Dimension
public int getSize getHeight ( Dimension rv) ()

Stores the width/height of this component into "return value" rv and returns rv. If rv is null a new Dimension object is allocated. This version of getSize is useful if the caller wants to avoid allocating a new Dimension object on the heap.
Returns the current height of this component. This method is preferable to writing component.getBounds().height, or component.getSize().height because it doesn't cause any heap allocations.

getLocation
isOpaque

public Point
public boolean getLocation isOpaque ( Point rv) ()

Stores the x,y origin of this component into "return value" rv and returns rv. If rv is null a new Point is allocated. This version of getLocation is useful if the caller wants to avoid allocating a new Point object on the heap.
Returns true if this component is completely opaque.

An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.

Subclasses that guarantee to always completely paint their contents should override this method and return true.

getX
setOpaque

public int void getX setOpaque () (boolean isOpaque)

Returns the current x coordinate of the component's origin. This method is preferable to writing component.getBounds().x, or component.getLocation().x because it doesn't cause any heap allocations.
If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through.

The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent.

getY
computeVisibleRect

Returns the current y coordinate of the component's origin. This method is preferable to writing component.getBounds().y, or component.getLocation().y because it doesn't cause any heap allocations.
Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors. The return value is stored in visibleRect.

getWidth
getVisibleRect

Returns the current width of this component. This method is preferable to writing component.getBounds().width, or component.getSize().width because it doesn't cause any heap allocations.
Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle:

getHeight
firePropertyChange

Returns the current height of this component. This method is preferable to writing component.getBounds().height, or component.getSize().height because it doesn't cause any heap allocations.
Supports reporting bound property changes. If oldValue and newValue are not equal and the PropertyChangeEvent listener list isn't empty, then fire a PropertyChange event to each listener. This method has an overloaded method for each primitive type. For example, here's how to write a bound property set method whose value is an integer:

isOpaque
firePropertyChange

Returns true if this component is completely opaque.
Reports a bound property change.

An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.

Subclasses that guarantee to always completely paint their contents should override this method and return true.

setOpaque
firePropertyChange

If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through.
Reports a bound property change.

The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent.

Parameters:

isOpaque - true if this component should be opaque
propertyName - the programmatic name of the property that was changed

computeVisibleRect
firePropertyChange

Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors. The return value is stored in visibleRect.
Reports a bound property change.

Parameters:

visibleRect - a Rectangle computed as the intersection of all visible rectangles for this component and all of its ancestors -- this is the return value for this method
propertyName - the programmatic name of the property that was changed

getVisibleRect
firePropertyChange

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.
Reports a bound property change.

firePropertyChange

Support for reporting bound property changes for boolean properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.
Reports a bound property change.

firePropertyChange
addPropertyChangeListener

Support for reporting bound property changes for integer properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to setting a bound property, such as setFont, setBackground, or setForeground.

Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

fireVetoableChange

Supports reporting constrained property changes. This method can be called when a constrained property has changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.

Parameters:

propertyName - the name of the property that was listened on

oldValue - the old value of the property

newValue - the new value of the property

Throws:

PropertyVetoException
- when the attempt to set the property is vetoed by the component

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.

Returns:

the top-level Container that this component is in, or null if not in any container

addAncestorListener

public 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. Events are also sent when the component or its ancestors are added or removed from the containment hierarchy.

Parameters:

listener - the AncestorListener to register

See Also:

AncestorEvent

removeAncestorListener

public void removeAncestorListener(AncestorListener listener)

Unregisters listener so that it will no longer receive AncestorEvents.

revalidate

public void revalidate()

Supports deferred automatic layout.

Calls invalidate and then adds this component's validateRoot to a list of components that need to be validated. Validation will occur after all currently pending events have been dispatched. In other words after this method is called, the first validateRoot (if any) found when walking up the containment hierarchy of this component will be validated. By default, JRootPane, JScrollPane, and JTextField return true from isValidateRoot.

This method will automatically be called on this component when a property value changes such that size, location, or internal layout of this component has been affected. This automatic updating differs from the AWT because programs generally no longer need to invoke validate to get the contents of the GUI to update.

isValidateRoot

public 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. Returns false by default. JScrollPane overrides this method and returns true.

isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()

Returns true if this component tiles its children -- that is, if it can guarantee that the children will not overlap. The repainting system is substantially more efficient in this common case. JComponent subclasses that can't make this guarantee, such as JLayeredPane, should override this method to return false.

Returns:

always returns true

paintImmediately

public 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.

It's rarely necessary to call this method. In most cases it's more efficient to call repaint, which defers the actual painting and can collapse redundant requests into a single paint call. This method is useful if one needs to update the display while the current event is being dispatched.

paintImmediately

setDoubleBuffered

public void setDoubleBuffered(boolean aFlag)

Sets whether the this component should use a buffer to paint. If set to true, all the drawing from this component will be done in an offscreen painting buffer. The offscreen painting buffer will the be copied onto the screen. Swings painting system always uses a maximum of one double buffer. If a Component is buffered and one of its ancestor is also buffered, the ancestor buffer will be used.

paramString

Returns a string representation of this JComponent. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.