All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JComponent

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent

public abstract class JComponent
extends Container
implements Serializable
The base class for the Swing components. JComponent provides: Keystroke Handling
The JComponent architecture makes it easy to handle keyboard events in nested components. You register interest in a particular combination of keystrokes by creating a KeyStroke object and registering it with the component. When you register the keystroke combination and its associated action, you also specify one of the following conditions to determine when the action is initiated: Action objects
Action-interface objects provide a single point of control for program actions. For example, a toolbar icon and a menu item can reference the same Action object. When the Action object is disabled, the GUI items that reference it are automatically disabled. The Action interface extends ActionListener, specifying an enabled property as well as properties for text-descriptions and graphic icons.

Compound Borders
Insets (the space between the edges of the component and the area it is drawn in) can be specified with a blank border. In addition, many border styles are available, which can be combined to create compound borders.

Simple Dialog Construction
The JOptionPane class provides a variety of static methods that you can invoke to create and display both message dialogs and user-choice dialogs in a variety of formats. The "message" displayed in the dialog can be a string, a string-generating object, or an arbitrary component. You can also replace the choice-buttons with components you specify for user-selections.

For example, the following line creates a simple message dialog that requires the user's confirmation:

JOptionPane.showMessageDialog(null, "The file will be deleted.");
Additional options are described in the JOptionPane class.

Support for Accessibility
Swing has built-in support for developers to make products that are compatible with Assistive Technologies (for alternative interfaces like, for example, braille.) All of the Swing components implement the Accessible interface and, where appropriate, the AccessibleText interface. JComponent contains all of the methods defined in the Accessible interface. Classes which extend JComponent can implement this Accessible by adding implements Accessible to the class description and by providing a localized Accessible Name for the component by calling its setAccessibleName method.

See Also:
KeyStroke, Action, setBorder, registerKeyboardAction, JOptionPane, setDebugGraphicsOptions, setToolTipText, setAutoscrolls, getAccessibleName

Variable Index

 o accessibleDescription
 o accessibleName
--- Accessibility Support --- JComponent will contain all of the methods in interface Accessible, though it won't actally implement the interface - that will be up to the individual objects which extend JComponent.
 o accessibleParent
 o listenerList
 o 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".
 o ui
 o UNDEFINED_CONDITION
Constant used by some of the apis to mean that no condition is defined.
 o WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used for registerKeyboardAction() which means that the comand should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.
 o WHEN_FOCUSED
Constant used for registerKeyboardAction() which means that the command should be invoked when the component has the focus.
 o WHEN_IN_FOCUSED_WINDOW
Constant used for registerKeyboardAction() which 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 Index

 o JComponent()
Default JComponent constructor.
 o JComponent(LayoutManager2)
Construct the JComponent using a JDK 1.1 layout manager.

Method Index

 o addAccessibleSelection(int)
Adds the nth selected item in the object to the object's selection.
 o addAncestorListener(AncestorListener)
Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible / invisible.
 o addNotify()
Notification to this component that it now has a parent component.
 o addPropertyChangeListener(PropertyChangeListener)
Add a PropertyChangeListener to the listener list.
 o addVetoableChangeListener(VetoableChangeListener)
Add a VetoableChangeListener to the listener list.
 o clearAccessibleSelection()
Clears the selection in the object, so that nothing in the object is selected.
 o computeVisibleRect(Rectangle)
Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors.
 o createToolTip()
Returns the instance of JToolTip that should be used to display the tooltip.
 o doAccessibleAction(int)
Perform the nth Action on the object
 o firePropertyChange(String, boolean, boolean)
 o firePropertyChange(String, byte, byte)
 o firePropertyChange(String, char, char)
 o firePropertyChange(String, double, double)
 o firePropertyChange(String, float, float)
 o firePropertyChange(String, int, int)
 o firePropertyChange(String, long, long)
 o firePropertyChange(String, Object, Object)
Support for reporting bound property changes.
 o firePropertyChange(String, short, short)
 o fireVetoableChange(String, Object, Object)
Support for reporting constrained property changes.
 o getAccessibleActionCount()
Returns the number of Actions available in this object If there is more than one, the first one is the "default" action (if any action is considered "default").
 o getAccessibleActionDescription(int)
Return a description of the nth action of the object.
 o getAccessibleAt(Point)
Returns the Accessible child contained at the local coordinate Point, if one exists.
 o getAccessibleChild(int)
Return the nth Accessible child of the object.
 o getAccessibleChildrenCount()
Returns the number of accessible children in the object.
 o getAccessibleDescription()
Get the accessible description of this object.
 o getAccessibleName()
Get the accessible name of this object.
 o getAccessibleParent()
Get the Accessible parent of this object.
 o getAccessibleRole()
Get the role of this object.
 o getAccessibleSelection(int)
Returns an Accessible representing the nth selected item in the object.
 o getAccessibleSelectionCount()
Returns the number of items currently selected.
 o getAccessibleStateSet()
Get the state of this object.
 o getAccessibleText()
Gets the AccessibleText interface for the component.
 o getAccessibleValue()
Get the value of this object as a String.
 o getActionForKeyStroke(KeyStroke)
Return the object that will perform the action registered for a given keystroke.
 o getAlignmentX()
 o getAlignmentY()
 o getAutoscrolls()
Returns true if this component automatically scrolls its contents when dragged, (when contained in a component that supports scrolling, like JViewport
 o getBorder()
Returns the border of this component or null if no border is currently set.
 o getBounds(Rectangle)
Store the bounds of this component into "return value" rv and return rv.
 o getClientProperties()
Support for managing a small set of per-instance properties.
 o getClientProperty(Object)
A convenience method for looking up a property value.
 o getComponentGraphics(Graphics)
Returns the graphics object used to paint this component.
 o getConditionForKeyStroke(KeyStroke)
Return the condition that determines whether a registered action occurs in response to the specified keystroke.
 o getDebugGraphicsOptions()
Returns the state of graphics debugging.
 o getGraphics()
Returns this component's graphics context, which lets you draw on a component.
 o getHeight()
Return the current height of this component.
 o getInsets()
If a border has been set on this component, returns the border's insets, else calls super.getInsets.
 o getLocation(Point)
Store the x,y origin of this component into "return value" rv and return rv.
 o getMaximumSize()
If the maximumSize has been set to a non-null value just return it.
 o getMinimumSize()
If the minimumSize has been set to a non-null value just return it.
 o getNextAccessibleSibling()
Get the next sibling of this Accessible, if a preferred one exists.
 o getNextFocusableComponent()
Return the next focusable component or null if the focus manager should choose the next focusable component automatically
 o getPreferredSize()
If the preferredSize has been set to a non-null value just return it.
 o getPreviousAccessibleSibling()
Get the previous sibling of this Accessible, if a preferred one exists.
 o getRegisteredKeyStrokes()
Return the KeyStrokes that will initiate registered actions.
 o getSize(Dimension)
Store the width/height of this component into "return value" rv and return rv.
 o getToolTipText()
Return the tooltip string that has been set with setToolTipText()
 o getToolTipText(MouseEvent)
Returns the string to be used as the tooltip for event.
 o getUIClassID()
Return the UIDefaults key used to look up the name of the swing.plaf.ComponentUI class that defines the look and feel for this component.
 o getVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this components visible rectangle:
 new Rectangle(0, 0, getSize.width(), getSize().height());
 
and all of its ancestors visible Rectangles.
 o getWidth()
Return the current width of this component.
 o getWindowAncestor()
Returns the top-level window ancestor of this component, or null if this component has not been added to any window.
 o getX()
Return the current x coordinate of the components origin.
 o getY()
Return the current y coordinate of the components origin.
 o grabFocus()
Set the focus on the receiving component.
 o hasFocus()
Returns true if this Component has the keyboard focus.
 o isDoubleBuffered()
Return whether the receiving component should use a buffer to paint.
 o isFocusCycleRoot()
Override this method and return true if your component is the root of of a component tree with its own focus cycle.
 o isFocusTraversable()
Identifies whether or not this component can receive the focus.
 o isLightweightComponent(Component)
Returns true if this component is a lightweight, i.e.
 o isManagingFocus()
Override this method and return true if your JComponent manages focus.
 o isOpaque()
Returns true if this component is completely opaque.
 o isOptimizedDrawingEnabled()
Returns true if this component tiles its children, i.e.
 o isPaintingTile()
Returns true if the receiving component is currently painting a tile.
 o isRequestFocusEnabled()
Return whether the receiving component can obtain the focus by calling requestFocus
 o paint(Graphics)
This method is invoked by Swing to draw components.
 o paintBorder(Graphics)
Paint the components border.
 o paintChildren(Graphics)
protected void paintChildren(Graphics g) { super.paint(g); }
 o paintComponent(Graphics)
If the UI delegate is non-null, call its paint method.
 o paintImmediately(int, int, int, int)
Paint the specified region in this component and all of its descendants that overlap the region, immediately.
 o paintImmediately(Rectangle)
Paint the specified region now.
 o processKeyEvent(KeyEvent)
Override processKeyEvent to process events
 o processMouseMotionEvent(MouseEvent)
 o putClientProperty(Object, Object)
A convenience method for storing up a property value.
 o registerKeyboardAction(ActionListener, KeyStroke, int)
Register a new keyboard action.
 o removeAccessibleSelection(int)
Removes the nth selected item in the object from the object's selection.
 o removeAncestorListener(AncestorListener)
Unregisters listener so that it will no longer receive AncestorEvents

This method will migrate to java.awt.Component in the next major JDK release

 o removeNotify()
Notification to this component that it no longer has a parent component.
 o removePropertyChangeListener(PropertyChangeListener)
Remove a PropertyChangeListener from the listener list.
 o removeVetoableChangeListener(VetoableChangeListener)
Remove a VetoableChangeListener from the listener list.
 o repaint(long, int, int, int, int)
Adds the specified region to the dirty region list.
 o repaint(Rectangle)
Adds the specified region to the dirty region list.
 o requestDefaultFocus()
Request the focus for the component that should have the focus by default.
 o requestFocus()
Set focus on the receiving component if isRequestFocusEnabled returns true
 o resetKeyboardActions()
Unregister all keyboard actions
 o scrollRectToVisible(Rectangle)
Forwards the scrollRectToVisible() message to the JComponent's parent.
 o selectAllAccessibleSelection()
Causes every selected item in the object to be selected, if the object supports multiple selections (if getAccessibleStateSet returns a state that is MULTISELECTABLE).
 o setAccessibleDescription(String)
Set the accessible description of this object.
 o setAccessibleName(String)
Set the localized accessible name of this object.
 o setAccessibleParent(Accessible)
Set the Accessible parent of this object.
 o setAlignmentX(float)
Set the value of the alignmentX property.
 o setAlignmentY(float)
Set the value of the alignmentY property.
 o setApplet(Applet)
This method is a temporary workaround to enable applets.
 o setAutoscrolls(boolean)
If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport
 o setBorder(Border)
Sets the border of this component.
 o setBounds(int, int, int, int)
Moves and resizes this component.
 o setBounds(Rectangle)
Moves and resizes this component.
 o setClientProperties(Dictionary)
Replace the client properties dictionary for this component.
 o setDebugGraphicsOptions(int)
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children.
 o setDoubleBuffered(boolean)
Set whether the receiving component should use a buffer to paint.
 o setMaximumSize(Dimension)
Sets the maximumSize of this component to a constant value.
 o setMinimumSize(Dimension)
Sets the minimumSize of this component to a constant value.
 o setNextFocusableComponent(Component)
Specifies the next component to get the focus after this one, for example, when the tab key is pressed.
 o setPreferredSize(Dimension)
Set the preferred size of the receiving component.
 o setRequestFocusEnabled(boolean)
Set whether the receiving component can obtain the focus by calling requestFocus.
 o setToolTipText(String)
Registers the text to display in a ToolTip.
 o setUI(ComponentUI)
 o unregisterKeyboardAction(KeyStroke)
Unregister a keyboard action.
 o updateUI()
Notification from the UIFactory that the L&F has changed.

Variables

 o ui
 protected transient ComponentUI ui
 o listenerList
 protected EventListenerList listenerList
 o WHEN_FOCUSED
 public static final int WHEN_FOCUSED
Constant used for registerKeyboardAction() which means that the command should be invoked when the component has the focus.

 o WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
 public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used for registerKeyboardAction() which means that the comand should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.

 o WHEN_IN_FOCUSED_WINDOW
 public static final int WHEN_IN_FOCUSED_WINDOW
Constant used for registerKeyboardAction() which 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.

 o UNDEFINED_CONDITION
 public static final int UNDEFINED_CONDITION
Constant used by some of the apis to mean that no condition is defined.

 o TOOL_TIP_TEXT_KEY
 public static final 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".

 o accessibleName
 protected String accessibleName
--- Accessibility Support --- JComponent will contain all of the methods in interface Accessible, though it won't actally implement the interface - that will be up to the individual objects which extend JComponent.

 o accessibleDescription
 protected String accessibleDescription
 o accessibleParent
 protected Accessible accessibleParent

Constructors

 o JComponent
 public JComponent()
Default JComponent constructor.

 o JComponent
 public JComponent(LayoutManager2 layout)
Construct the JComponent using a JDK 1.1 layout manager. [The 1.1 version of the layout manager improves on the 1.0 version by adding a maximum size property, alignment capabilities, and the ability to mark a component as needing to be redrawn with the invalidate method.]

Methods

 o updateUI
 public void updateUI()
Notification from the UIFactory that the L&F has changed. An example implementation of this for JButton might be:
   public void updateUI() {
      setUI((ButtonUI)UIManager.getUI(this);
   }
  

 o setUI
 protected void setUI(ComponentUI x)
 o getUIClassID
 public String getUIClassID()
Return 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 the name of the ComponentUI subclass that defines their look and feel.

Returns:
The name of a ComponentUI subclass.
See Also:
getUI
 o getComponentGraphics
 protected Graphics getComponentGraphics(Graphics g)
Returns the graphics object used to paint this component. If DebugGraphics is turned on we create a new DebugGraphics object if neccessary otherwise we just configure the specified graphics objects foreground and font.

Returns:
A Graphics object configured for this component
 o paintComponent
 protected void paintComponent(Graphics g)
If the UI delegate is non-null, call its paint method. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (e.g. Graphics.translate()).

See Also:
paint
 o paintChildren
 protected void paintChildren(Graphics g)
protected void paintChildren(Graphics g) { super.paint(g); }

 o paintBorder
 protected void paintBorder(Graphics g)
Paint the components border.

See Also:
paint, setBorder
 o paint
 public void paint(Graphics g)
This method is 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.

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) delegates paint method should just override paintComponent.

Overrides:
paint in class Container
See Also:
paintComponent, paintBorder, paintChildren, getComponentGraphics, repaint
 o isPaintingTile
 public boolean isPaintingTile()
Returns true if the receiving 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.

 o isFocusCycleRoot
 public boolean isFocusCycleRoot()
Override this method and return true if your component is the root of of a component tree with its own focus cycle.

 o isManagingFocus
 public boolean isManagingFocus()
Override this method and return true if your JComponent manages focus. If your component manages focus, the focus manager will handle your component's children. All key event will be sent to your key listener including TAB and SHIFT+TAB. CONTROL + TAB and CONTROL + SHIFT + TAB will move the focus to the next / previous component.

 o setNextFocusableComponent
 public void setNextFocusableComponent(Component aComponent)
Specifies the next component to get the focus after this one, for example, when the tab key is pressed. Invoke this method to override the default focus-change sequence.

 o getNextFocusableComponent
 public Component getNextFocusableComponent()
Return the next focusable component or null if the focus manager should choose the next focusable component automatically

 o setRequestFocusEnabled
 public void setRequestFocusEnabled(boolean aFlag)
Set whether the receiving component can obtain the focus by calling requestFocus. The default value is true. Note: Setting this property to false will not prevent the focus manager from setting the focus to this component, it will prevent the component from getting the focus when the focus is requested explicitely. Override isFocusTraversable and return false if the component should never get the focus.

 o isRequestFocusEnabled
 public boolean isRequestFocusEnabled()
Return whether the receiving component can obtain the focus by calling requestFocus

See Also:
setRequestFocusEnabled
 o requestFocus
 public void requestFocus()
Set focus on the receiving component if isRequestFocusEnabled returns true

Overrides:
requestFocus in class Component
 o grabFocus
 public void grabFocus()
Set the focus on the receiving component. This method is for focus managers, you rarely want to call this method, use requestFocus() enstead.

 o setPreferredSize
 public void setPreferredSize(Dimension preferredSize)
Set the preferred size of the receiving component. if preferredSize is null, the UI will be asked for the preferred size

 o getPreferredSize
 public Dimension getPreferredSize()
If the preferredSize has been set to a non-null value just return it. If the UI delegates getPreferredSize() method returns a non null then value return that, otherwise defer to the components layout manager.

Returns:
the value of the preferredSize property.
Overrides:
getPreferredSize in class Container
See Also:
setPreferredSize
 o setMaximumSize
 public void setMaximumSize(Dimension maximumSize)
Sets the maximumSize of this component to a constant value. Subsequent calls to getMaximumSize will always return this value, the components UI will not be asked to compute it. Setting the maximumSize to null restores the default behavior.

See Also:
getMaximumSize
 o getMaximumSize
 public Dimension getMaximumSize()
If the maximumSize has been set to a non-null value just return it. If the UI delegates getMaximumSize() method returns a non null value then return that, otherwise defer to the components layout manager.

Returns:
the value of the maximumSize property.
Overrides:
getMaximumSize in class Container
See Also:
setMaximumSize
 o setMinimumSize
 public void setMinimumSize(Dimension minimumSize)
Sets the minimumSize of this component to a constant value. Subsequent calls to getMinimumSize will always return this value, the components UI will not be asked to compute it. Setting the minimumSize to null restores the default behavior.

See Also:
getMinimumSize
 o getMinimumSize
 public Dimension getMinimumSize()
If the minimumSize has been set to a non-null value just return it. If the UI delegates getMinimumSize() method returns a non null value then return that, otherwise defer to the components layout manager.

Returns:
the value of the minimumSize property.
Overrides:
getMinimumSize in class Container
See Also:
setMinimumSize
 o setBorder
 public void setBorder(Border border)
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 (e.g. margins and padding) regions for a swing component. Compound borders can be used to nest multiple borders within a single component.

This is a bound property.

Parameters:
border - the border to be rendered for this component
See Also:
Border, CompoundBorder
 o getBorder
 public Border getBorder()
Returns the border of this component or null if no border is currently set.

Returns:
the border object for this component
See Also:
setBorder
 o getInsets
 public Insets getInsets()
If a border has been set on this component, returns the border's insets, else calls super.getInsets.

Returns:
the value of the insets property.
Overrides:
getInsets in class Container
See Also:
setBorder
 o getAlignmentY
 public float getAlignmentY()
Returns:
the value of the alignmentY property.
Overrides:
getAlignmentY in class Container
See Also:
setAlignmentY, getAlignmentY
 o setAlignmentY
 public void setAlignmentY(float alignmentY)
Set the value of the alignmentY property.

See Also:
getAlignmentY
 o getAlignmentX
 public float getAlignmentX()
Returns:
the value of the alignmentX property.
Overrides:
getAlignmentX in class Container
See Also:
setAlignmentX, getAlignmentX
 o setAlignmentX
 public void setAlignmentX(float alignmentX)
Set the value of the alignmentX property.

See Also:
getAlignmentX
 o getGraphics
 public Graphics getGraphics()
Returns this component's graphics context, which lets you draw on a component. Use this method get a Graphics object and then invoke oeprations on that object to draw on the component.

Overrides:
getGraphics in class Component
 o setDebugGraphicsOptions
 public void setDebugGraphicsOptions(int debugOptions)
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. The value of debugOptions determines how the component should display this information: debug is bitwise OR'd into the current value. DebugGraphics.NONE_OPTION disables debugging. A value of 0 causes no changes to the debugging options.

 o getDebugGraphicsOptions
 public int getDebugGraphicsOptions()
Returns the state of graphics debugging.

See Also:
setDebugGraphicsOptions
 o registerKeyboardAction
 public void registerKeyboardAction(ActionListener anAction,
                                    KeyStroke aKeyStroke,
                                    int aCondition)
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 Condition 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.

See Also:
KeyStroke
 o unregisterKeyboardAction
 public void unregisterKeyboardAction(KeyStroke aKeyStroke)
Unregister a keyboard action.

See Also:
registerKeyboardAction
 o getRegisteredKeyStrokes
 public KeyStroke[] getRegisteredKeyStrokes()
Return the KeyStrokes that will initiate registered actions.

Returns:
an array of KeyStroke objects
See Also:
registerKeyboardAction
 o getConditionForKeyStroke
 public int getConditionForKeyStroke(KeyStroke aKeyStroke)
Return the condition that determines whether a registered action occurs in response to the specified keystroke.

Returns:
the action-keystroke condition
See Also:
registerKeyboardAction
 o getActionForKeyStroke
 public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
Return the object that will perform the action registered for a given keystroke.

Returns:
the ActionListener object invoked when the keystroke occurs
See Also:
registerKeyboardAction
 o resetKeyboardActions
 public void resetKeyboardActions()
Unregister all keyboard actions

See Also:
registerKeyboardAction
 o requestDefaultFocus
 public boolean requestDefaultFocus()
Request the focus for the component that should have the focus by default. The default implementation will recursively request the focus on the first component that is focus-traversable.

Returns:
false if the focus has not been set, otherwise return true
 o isFocusTraversable
 public boolean isFocusTraversable()
Identifies whether or not this component can receive the focus. A disabled button, for example, would return false.

Returns:
true if this component can receive the focus
Overrides:
isFocusTraversable in class Component
 o processKeyEvent
 protected void processKeyEvent(KeyEvent e)
Override processKeyEvent to process events

Overrides:
processKeyEvent in class Component
 o setToolTipText
 public void setToolTipText(String text)
Registers the text to display in a ToolTip.

Parameters:
text - The string to display when the cursor lingers over the component. If text is null, then it turns off tool tool tip for this component.
See Also:
TOOL_TIP_TEXT_KEY
 o getToolTipText
 public String getToolTipText()
Return the tooltip string that has been set with setToolTipText()

Returns:
the text of the tool tip
See Also:
TOOL_TIP_TEXT_KEY
 o getToolTipText
 public String getToolTipText(MouseEvent event)
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 extensize API to support differing tooltips at different locations, this method should be overridden.

 o createToolTip
 public JToolTip createToolTip()
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.

 o scrollRectToVisible
 public void scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as a JViewport, override this method and perform the scrolling.

See Also:
JViewport
 o setAutoscrolls
 public void setAutoscrolls(boolean autoscrolls)
If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport

See Also:
JViewport, getAutoscrolls
 o getAutoscrolls
 public boolean getAutoscrolls()
Returns true if this component automatically scrolls its contents when dragged, (when contained in a component that supports scrolling, like JViewport

See Also:
JViewport, setAutoscrolls
 o processMouseMotionEvent
 protected void processMouseMotionEvent(MouseEvent e)
Overrides:
processMouseMotionEvent in class Component
 o getNextAccessibleSibling
 public Accessible getNextAccessibleSibling()
Get the next sibling of this Accessible, if a preferred one exists. This should generally return the next item in the tab order, if that item implements Accessible

Returns:
the next Accessible, if there is one
 o getPreviousAccessibleSibling
 public Accessible getPreviousAccessibleSibling()
Get the previous sibling of this Accessible, if a preferred one exists. This should generally return the previous item in the tab order, if that item implements Accessible

Returns:
the previous Accessible, if there is one
 o getAccessibleAt
 public Accessible getAccessibleAt(Point p)
Returns the Accessible child contained at the local coordinate Point, if one exists.

Returns:
the Accessible at the specified location, if it exists
 o getAccessibleName
 public String getAccessibleName()
Get the accessible name of this object. This should almost never return java.awt.Component.getName(), as that generally isn't a localized name, and doesn't have meaning for the user. If the object is fundamentally a text object (e.g. a menu item), the accessible name should be the text of the object (e.g. "save"). If the object has a tooltip, the tooltip text may also be an appropriate String to return.

Returns:
the localized name of the object -- can be null if this object does not have a name
See Also:
setAccessibleName
 o setAccessibleName
 public void setAccessibleName(String s)
Set the localized accessible name of this object.

Parameters:
s - the new localized name of the object.
See Also:
getAccessibleName
 o getAccessibleDescription
 public String getAccessibleDescription()
Get the accessible description of this object. This should be a concise, localized description of what this object is - what is it's meaning to the user. If the object has a tooltip, the tooltip text may be an appropriate string to return, assuming it contains a concise description of the object (instead of just the name of the object - e.g. a "Save" icon on a toolbar that had "save" as the tooltip text shouldn't return the tooltip text as the description, but something like "Saves the current text document" instead).

Returns:
the localized description of the object -- can be null if this object does not have a description
See Also:
setAccessibleDescription
 o setAccessibleDescription
 public void setAccessibleDescription(String s)
Set the accessible description of this object.

Parameters:
s - the new localized description of the object
See Also:
getAccessibleDescription
 o getAccessibleStateSet
 public AccessibleStateSet getAccessibleStateSet()
Get the state of this object.

Returns:
an instance of AccessibleStateSet containing the current state set of the object
See Also:
AccessibleState
 o getAccessibleRole
 public AccessibleRole getAccessibleRole()
Get the role of this object.

Returns:
an instance of AccessibleRole describing the role of the object
See Also:
AccessibleRole
 o getAccessibleValue
 public String getAccessibleValue()
Get the value of this object as a String. This should almost never return java.Object.toString(), as that is not a localized, human readable representation of the value of the object.

Returns:
human readable value of the object -- can be null if this object does not have a value
 o getAccessibleParent
 public Accessible getAccessibleParent()
Get the Accessible parent of this object. If the parent of this object implements Accessible, this method should simply return getParent().

Returns:
the Accessible parent of this object -- can be null if this object does not have an Accessible parent
 o setAccessibleParent
 public void setAccessibleParent(Accessible a)
Set the Accessible parent of this object. This is meant to be used only in the situations where the actual component's parent should not be treated as the component's accessible parent.

 o getAccessibleChildrenCount
 public int getAccessibleChildrenCount()
Returns the number of accessible children in the object. If all of the children of this object implement Accessible, than this method should return the number of children of this object.

Returns:
the number of accessible children in the object.
 o getAccessibleChild
 public Accessible getAccessibleChild(int i)
Return the nth Accessible child of the object.

Parameters:
i - zero-based index of child
Returns:
the nth Accessible child of the object
 o getAccessibleActionCount
 public int getAccessibleActionCount()
Returns the number of Actions available in this object If there is more than one, the first one is the "default" action (if any action is considered "default").

Returns:
the number of Actions in this object
 o getAccessibleActionDescription
 public String getAccessibleActionDescription(int i)
Return a description of the nth action of the object. This description should be human-readable; by default it currently isn't...

Parameters:
i - zero-based index of the actions
Returns:
a description of the nth action
 o doAccessibleAction
 public boolean doAccessibleAction(int i)
Perform the nth Action on the object

Parameters:
i - zero-based index of actions
Returns:
whether the action was performed or not.
 o getAccessibleText
 public AccessibleText getAccessibleText()
Gets the AccessibleText interface for the component. If the component does not speak AccessibleText, or have a proxy which does, this method returns null.

Returns:
the AccessibleText of the object.
See Also:
AccessibleText
 o getAccessibleSelectionCount
 public int getAccessibleSelectionCount()
Returns the number of items currently selected. If no items are selected, the return value will be 0.

Returns:
the number of items currently selected.
 o getAccessibleSelection
 public Accessible getAccessibleSelection(int i)
Returns an Accessible representing the nth selected item in the object. If there isn't a selection, or there are fewer items selcted than the integer passed in, the return value will be null.

Parameters:
i - the zero-based index of selected items
Returns:
an Accessible containing the selected item
 o addAccessibleSelection
 public void addAccessibleSelection(int i)
Adds the nth selected item in the object to the object's selection. If the object supports multiple selections, (the method getAccessibleStateSet returns a state that is MULTISELECTABLE) the nth item is added to any existing selection, otherwse it replaces any existing selection in the objct. If the nth item is already selected, this method has no effect.

Parameters:
i - the zero-based index of selectable items
See Also:
getAccessibleStateSet
 o removeAccessibleSelection
 public void removeAccessibleSelection(int i)
Removes the nth selected item in the object from the object's selection. If the nth item isn't currently selected, this method has no effect.

Parameters:
i - the zero-based index of selectable items
 o clearAccessibleSelection
 public void clearAccessibleSelection()
Clears the selection in the object, so that nothing in the object is selected.

 o selectAllAccessibleSelection
 public void selectAllAccessibleSelection()
Causes every selected item in the object to be selected, if the object supports multiple selections (if getAccessibleStateSet returns a state that is MULTISELECTABLE).

See Also:
getAccessibleStateSet
 o getClientProperties
 public Dictionary getClientProperties()
Support for managing a small set of per-instance properties. Callers can use the clientProperties dictionary to annotate components that were created by another module, e.g. a layout manager might store per child constraints this way. For example:
 componentA.getClientProperties().put("to the left of", componentB);
 

The clientProperties 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.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
a non null Dictionary
See Also:
setClientProperties
 o setClientProperties
 public void setClientProperties(Dictionary x)
Replace the client properties dictionary for this component.

This method will migrate to java.awt.Component in the next major JDK release

See Also:
getClientProperties
 o getClientProperty
 public final Object getClientProperty(Object key)
A convenience method for looking up a property value. It is equivalent to:
 getClientProperties().get(key);
 

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the value of this property or null
See Also:
getClientProperties
 o putClientProperty
 public final void putClientProperty(Object key,
                                     Object value)
A convenience method for storing up a property value. It is equivalent to:
 getClientProperties().put(key, value);
 
If value is null this method will remove the property

This method will migrate to java.awt.Component in the next major JDK release

See Also:
getClientProperties
 o isLightweightComponent
 public static boolean isLightweightComponent(Component c)
Returns true if this component is a lightweight, i.e. if it doesn't have a native window system peer.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this component is a lightweight
 o setBounds
 public void setBounds(int x,
                       int y,
                       int w,
                       int h)
Moves and resizes this component.

Overrides:
setBounds in class Component
See Also:
setBounds
 o setBounds
 public void setBounds(Rectangle r)
Moves and resizes this component.

Overrides:
setBounds in class Component
See Also:
setBounds
 o getBounds
 public Rectangle getBounds(Rectangle rv)
Store the bounds of this component into "return value" rv and return rv. This version of getBounds() is useful if the caller wants to avoid allocating a new Rectangle object on the heap.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
rv - the return value, modified to the components bounds
Returns:
rv
 o getSize
 public Dimension getSize(Dimension rv)
Store the width/height of this component into "return value" rv and return rv. This version of getSize() is useful if the caller wants to avoid allocating a new Dimension object on the heap.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
rv - the return value, modified to the components size
Returns:
rv
 o getLocation
 public Point getLocation(Point rv)
Store the x,y origin of this component into "return value" rv and return rv. This version of getLocation() is useful if the caller wants to avoid allocating a new Point object on the heap.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
rv - the return value, modified to the components location
Returns:
rv
 o getX
 public int getX()
Return the current x coordinate of the components origin. This method is preferable to writing component.getBounds().x, or component.getLocation().x because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current x coordinate of the components origin.
 o getY
 public int getY()
Return the current y coordinate of the components origin. This method is preferable to writing component.getBounds().y, or component.getLocation().y because it doesn't cause any heap allocations.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current y coordinate of the components origin.
 o getWidth
 public int getWidth()
Return 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.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current width of this component.
 o getHeight
 public int getHeight()
Return 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.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the current height of this component.
 o hasFocus
 public boolean hasFocus()
Returns true if this Component has the keyboard focus.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this Component has the keyboard focus.
 o isOpaque
 public boolean isOpaque()
Returns true if this component is completely opaque. Subclasses that guarantee to always completely paint their contents should override this method and return true.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this component is completely opaque.
 o computeVisibleRect
 public 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. The return value is stored in visibleRect

This method will migrate to java.awt.Component in the next major JDK release

See Also:
getVisibleRect
 o getVisibleRect
 public Rectangle getVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this components visible rectangle:
 new Rectangle(0, 0, getSize.width(), getSize().height());
 
and all of its ancestors visible Rectangles.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the visible rectangle
 o firePropertyChange
 protected void firePropertyChange(String propertyName,
                                   Object oldValue,
                                   Object newValue)
Support for 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 int:
 public void setFoo(int newValue) {
     int oldValue = foo;
     foo = newValue;
     firePropertyChange("foo", oldValue, newValue);
 }
 

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
propertyName - The programmatic name of the property that was changed.
oldValue - The old value of the property.
newValue - The new value of the property.
See Also:
PropertyChangeSupport
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                byte oldValue,
                                byte newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                char oldValue,
                                char newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                short oldValue,
                                short newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                int oldValue,
                                int newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                long oldValue,
                                long newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                float oldValue,
                                float newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                double oldValue,
                                double newValue)
See Also:
firePropertyChange
 o firePropertyChange
 public void firePropertyChange(String propertyName,
                                boolean oldValue,
                                boolean newValue)
See Also:
firePropertyChange
 o addPropertyChangeListener
 public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Add 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, e.g. 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.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The PropertyChangeListener to be added
 o removePropertyChangeListener
 public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The PropertyChangeListener to be removed
 o fireVetoableChange
 protected void fireVetoableChange(String propertyName,
                                   Object oldValue,
                                   Object newValue) throws PropertyVetoException
Support for 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.

This method will migrate to java.awt.Component in the next major JDK release

Throws: PropertyVetoException
when the attempt to set the property is vetoed by the receiver.
 o addVetoableChangeListener
 public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
Add a VetoableChangeListener to the listener list. The listener is registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The VetoableChangeListener to be added
 o removeVetoableChangeListener
 public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
Remove a VetoableChangeListener from the listener list. This removes a VetoableChangeListener that was registered for all properties.

This method will migrate to java.awt.Component in the next major JDK release

Parameters:
listener - The VetoableChangeListener to be removed
 o getWindowAncestor
 public Window getWindowAncestor()
Returns the top-level window ancestor of this component, or null if this component has not been added to any window.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
the top-level window which this component is in.
 o 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 / invisible. Events are also sent when the component or its ancestors are added or removed from the Component hierarchy

This method will migrate to java.awt.Component in the next major JDK release

See Also:
AncestorEvent
 o removeAncestorListener
 public void removeAncestorListener(AncestorListener listener)
Unregisters listener so that it will no longer receive AncestorEvents

This method will migrate to java.awt.Component in the next major JDK release

See Also:
addAncestorListener
 o addNotify
 public void addNotify()
Notification to this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners.

Overrides:
addNotify in class Container
See Also:
registerKeyboardAction
 o removeNotify
 public void removeNotify()
Notification to this component that it no longer has a parent component. When this method is invoked, any KeyboardActions set up in the the chain of parent components are removed.

Overrides:
removeNotify in class Container
See Also:
registerKeyboardAction
 o repaint
 public void repaint(long tm,
                     int x,
                     int y,
                     int width,
                     int height)
Adds the specified region to the dirty region list. The component will be repainted after all of the currently pending events have been dispatched.

Overrides:
repaint in class Component
See Also:
RepaintManager
 o repaint
 public void repaint(Rectangle r)
Adds the specified region to the dirty region list. The component will be repainted after all of the currently pending events have been dispatched.

See Also:
RepaintManager
 o isOptimizedDrawingEnabled
 public boolean isOptimizedDrawingEnabled()
Returns true if this component tiles its children, i.e. 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, e.g. JLayeredPane, should override this method to return false.

This method will migrate to java.awt.Component in the next major JDK release

Returns:
true if this components children don't overlap
 o paintImmediately
 public void paintImmediately(int x,
                              int y,
                              int w,
                              int h)
Paint the specified region in this component and all of its descendants that overlap the region, immediately.

It's rarely neccessary 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.

This method will migrate to java.awt.Component in the next major JDK release

See Also:
repaint
 o paintImmediately
 public void paintImmediately(Rectangle r)
Paint the specified region now.

This method will migrate to java.awt.Component in the next major JDK release

 o setDoubleBuffered
 public void setDoubleBuffered(boolean aFlag)
Set whether the receiving 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. Swing's painting system always use 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.

 o isDoubleBuffered
 public boolean isDoubleBuffered()
Return whether the receiving component should use a buffer to paint.

 o setApplet
 public static void setApplet(Applet applet)
This method is a temporary workaround to enable applets. This method will go away before Swing 1.0


All Packages  Class Hierarchy  This Package  Previous  Next  Index