Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR-209 (Final Approval Ballot)

javax.swing
Class JComponent

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.io.Serializable
Direct Known Subclasses:
AbstractButton, Box, Box.Filler, JComboBox, JInternalFrame, JLabel, JLayeredPane, JList, JMenuBar, JOptionPane, JPanel, JPopupMenu, JProgressBar, JRootPane, JScrollBar, JScrollPane, JSeparator, JSlider, JSpinner, JTabbedPane, JTable, JTableHeader, JTextComponent, JTree, JViewport

public abstract class JComponent
extends java.awt.Container
implements java.io.Serializable

The base class for all Swing components except top-level containers. To use a component that inherits from JComponent, you must place the component in a containment hierarchy whose root is a top-level Swing container. Swing Components and the Containment Hierarchy, a section in The Java Tutorial.

The JComponent class provides:

For more information on these subjects, see the Swing package description and The Java Tutorial section The JComponent Class.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.

Restrictions

Implementations of JComponent in JSR-209 may exhibit the following restrictions:

See Also:
KeyStroke, Action, setBorder(javax.swing.border.Border), registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int), JOptionPane, setAutoscrolls(boolean)

Field Summary
protected  EventListenerList listenerList
          A list of event listeners for this component.
static java.lang.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".
static int UNDEFINED_CONDITION
          Constant used by some of the APIs to mean that no condition is defined.
static int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
          Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.
static int WHEN_FOCUSED
          Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus.
static int WHEN_IN_FOCUSED_WINDOW
          Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JComponent()
          Default JComponent constructor.
 
Method Summary
 void addAncestorListener(AncestorListener listener)
          Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible or invisible.
 void addNotify()
          Notifies this component that it now has a parent component.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener for a specific property.
 void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Adds a VetoableChangeListener to the listener list.
 void computeVisibleRect(Rectangle visibleRect)
          Returns the Component's "visible rect rectangle" - the intersection of the visible rectangles for this component and all of its ancestors.
 boolean contains(int x, int y)
          Gives the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing.
 void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, byte oldValue, byte newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, char oldValue, char newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, double oldValue, double newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, float oldValue, float newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
          Reports a bound property change.
 void firePropertyChange(java.lang.String propertyName, long oldValue, long newValue)
          Reports a bound property change.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Supports reporting bound property changes.
 void firePropertyChange(java.lang.String propertyName, short oldValue, short newValue)
          Reports a bound property change.
protected  void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Supports reporting constrained property changes.
 java.awt.event.ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
          Returns the object that will perform the action registered for a given keystroke.
 ActionMap getActionMap()
          Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.
 float getAlignmentX()
          Overrides Container.getAlignmentX to return the vertical alignment.
 float getAlignmentY()
          Overrides Container.getAlignmentY to return the horizontal alignment.
 AncestorListener[] getAncestorListeners()
          Returns an array of all the ancestor listeners registered on this component.
 boolean getAutoscrolls()
          Gets the autoscrolls property.
 Border getBorder()
          Returns the border of this component or null if no border is currently set.
 Rectangle getBounds(Rectangle rv)
          Stores the bounds of this component into "return value" rv and returns rv.
 java.lang.Object getClientProperty(java.lang.Object key)
          Returns the value of the property with the specified key.
protected  java.awt.Graphics getComponentGraphics(java.awt.Graphics g)
          Returns the graphics object used to paint this component.
 int getConditionForKeyStroke(KeyStroke aKeyStroke)
          Returns the condition that determines whether a registered action occurs in response to the specified keystroke.
static java.util.Locale getDefaultLocale()
          Returns the default locale used to initialize each JComponent's locale property upon creation.
 java.awt.Graphics getGraphics()
          Returns this component's graphics context, which lets you draw on a component.
 int getHeight()
          Returns the current height of this component.
 InputMap getInputMap()
          Returns the InputMap that is used when the component has focus.
 InputMap getInputMap(int condition)
          Returns the InputMap that is used during condition.
 InputVerifier getInputVerifier()
          Returns the input verifier for this component.
 java.awt.Insets getInsets()
          If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
 java.awt.Insets getInsets(java.awt.Insets insets)
          Returns an Insets object containing this component's inset values.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this JComponent.
 Point getLocation(Point rv)
          Stores the x,y origin of this component into "return value" rv and returns rv.
 Dimension getMaximumSize()
          If the maximum size has been set to a non-null value just returns it.
 Dimension getMinimumSize()
          If the minimum size has been set to a non-null value just returns it.
 Dimension getPreferredSize()
          If the preferredSize has been set to a non-null value just returns it.
 java.beans.PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the PropertyChangeListeners added to this Component with addPropertyChangeListener().
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
          Returns an array of all the listeners which have been associated with the named property.
 KeyStroke[] getRegisteredKeyStrokes()
          Returns the KeyStrokes that will initiate registered actions.
 Dimension getSize(Dimension rv)
          Stores the width/height of this component into "return value" rv and returns rv.
 java.lang.String getToolTipText()
          Returns the tooltip string that has been set with setToolTipText.
 boolean getVerifyInputWhenFocusTarget()
          Returns the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus.
 java.beans.VetoableChangeListener[] getVetoableChangeListeners()
          Returns an array of all the vetoable change listeners registered on this component.
 Rectangle getVisibleRect()
          Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle:
 int getWidth()
          Returns the current width of this component.
 int getX()
          Returns the current x coordinate of the component's origin.
 int getY()
          Returns the current y coordinate of the component's origin.
 boolean isDoubleBuffered()
          Returns whether this component should use a buffer to paint.
 boolean isMaximumSizeSet()
          Returns true if the maximum size has been set to a non-null value otherwise returns false.
 boolean isMinimumSizeSet()
          Returns true if the minimum size has been set to a non-null value otherwise returns false.
 boolean isOpaque()
          Returns true if this component is completely opaque.
 boolean isOptimizedDrawingEnabled()
          Returns true if this component tiles its children -- that is, if it can guarantee that the children will not overlap.
 boolean isPaintingTile()
          Returns true if the component is currently painting a tile.
 boolean isPreferredSizeSet()
          Returns true if the preferred size has been set to a non-null value otherwise returns false.
 boolean isRequestFocusEnabled()
          Returns true if this JComponent should get focus; otherwise returns false.
 boolean isValidateRoot()
          If this method returns true, revalidate calls by descendants of this component will cause the entire tree beginning with this root to be validated.
 void paint(java.awt.Graphics g)
          Invoked by Swing to draw components.
protected  void paintBorder(java.awt.Graphics g)
          Paints the component's border.
protected  void paintChildren(java.awt.Graphics g)
          Paints this component's children.
protected  void paintComponent(java.awt.Graphics g)
          Calls the UI delegate's paint method, if the UI delegate is non-null.
 void paintImmediately(int x, int y, int w, int h)
          Paints the specified region in this component and all of its descendants that overlap the region, immediately.
 void paintImmediately(Rectangle r)
          Paints the specified region now.
protected  java.lang.String paramString()
          Returns a string representation of this JComponent.
 void print(java.awt.Graphics g)
          Invoke this method to print the component.
 void printAll(java.awt.Graphics g)
          Invoke this method to print the component.
protected  void printBorder(java.awt.Graphics g)
          Prints the component's border.
protected  void printChildren(java.awt.Graphics g)
          Prints this component's children.
protected  void printComponent(java.awt.Graphics g)
          This is invoked during a printing operation.
protected  void processComponentKeyEvent(java.awt.event.KeyEvent e)
          Processes any key events that the component itself recognizes.
protected  boolean processKeyBinding(KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)
          Invoked to process the key bindings for ks as the result of the KeyEvent e.
protected  void processKeyEvent(java.awt.event.KeyEvent e)
          Overrides processKeyEvent to process events.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent e)
          Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
 void putClientProperty(java.lang.Object key, java.lang.Object value)
          Adds an arbitrary key/value "client property" to this component.
 void registerKeyboardAction(java.awt.event.ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
          This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similiar behavior.
 void registerKeyboardAction(java.awt.event.ActionListener anAction, java.lang.String aCommand, KeyStroke aKeyStroke, int aCondition)
          This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similiar behavior.
 void removeAncestorListener(AncestorListener listener)
          Unregisters listener so that it will no longer receive AncestorEvents.
 void removeNotify()
          Notifies this component that it no longer has a parent component.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener for a specific property.
 void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Removes a VetoableChangeListener from the listener list.
 void repaint(long tm, int x, int y, int width, int height)
          Adds the specified region to the dirty region list if the component is showing.
 void repaint(Rectangle r)
          Adds the specified region to the dirty region list if the component is showing.
 void requestFocus()
           
 boolean requestFocus(boolean temporary)
          JComponent overrides requestFocus solely to make the method public so that UI implementations can cause temporary focus changes.
 boolean requestFocusInWindow()
           
protected  boolean requestFocusInWindow(boolean temporary)
          JComponent overrides requestFocusInWindow solely to make the method public so that UI implementations can cause temporary focus changes.
 void resetKeyboardActions()
          Unregisters all the bindings in the first tier InputMaps and ActionMap.
 void reshape(int x, int y, int w, int h)
          Moves and resizes this component.
 void revalidate()
          Supports deferred automatic layout.
 void scrollRectToVisible(Rectangle aRect)
          Forwards the scrollRectToVisible() message to the JComponent's parent.
 void setActionMap(ActionMap am)
          Sets the ActionMap to am.
 void setAlignmentX(float alignmentX)
          Sets the the vertical alignment.
 void setAlignmentY(float alignmentY)
          Sets the the horizontal alignment.
 void setAutoscrolls(boolean autoscrolls)
          Sets the autoscrolls property.
 void setBackground(Color bg)
          Sets the background color of this component.
 void setBorder(Border border)
          Sets the border of this component.
static void setDefaultLocale(java.util.Locale l)
          Sets the default locale used to initialize each JComponent's locale property upon creation.
 void setDoubleBuffered(boolean aFlag)
          Sets whether the this component should use a buffer to paint.
 void setEnabled(boolean enabled)
          Sets whether or not this component is enabled.
 void setFont(Font font)
          Sets the font for this component.
 void setForeground(Color fg)
          Sets the foreground color of this component.
 void setInputMap(int condition, InputMap map)
          Sets the InputMap to use under the condition condition to map.
 void setInputVerifier(InputVerifier inputVerifier)
          Sets the input verifier for this component.
 void setMaximumSize(Dimension maximumSize)
          Sets the maximum size of this component to a constant value.
 void setMinimumSize(Dimension minimumSize)
          Sets the minimum size of this component to a constant value.
 void setOpaque(boolean isOpaque)
          If true the component paints every pixel within its bounds.
 void setPreferredSize(Dimension preferredSize)
          Sets the preferred size of this component.
 void setRequestFocusEnabled(boolean requestFocusEnabled)
          Provides a hint as to whether or not this JComponent should get focus.
 void setToolTipText(java.lang.String text)
          Registers the text to display in a tool tip.
 void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
          Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus.
 void setVisible(boolean aFlag)
          Makes the component visible or invisible.
 void unregisterKeyboardAction(KeyStroke aKeyStroke)
          This method is now obsolete.
 void update(java.awt.Graphics g)
          Calls paint.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, list, list, paintComponents, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getCursor, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getSize, getToolkit, getTreeLock, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, setBounds, setBounds, setCursor, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
A list of event listeners for this component.


WHEN_FOCUSED

public static final int WHEN_FOCUSED
Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus.

See Also:
Constant Field Values

WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

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

See Also:
Constant Field Values

WHEN_IN_FOCUSED_WINDOW

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

See Also:
Constant Field Values

UNDEFINED_CONDITION

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

See Also:
Constant Field Values

TOOL_TIP_TEXT_KEY

public static final java.lang.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".

See Also:
Constant Field Values
Constructor Detail

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.

See Also:
getDefaultLocale()
Method Detail

getComponentGraphics

protected java.awt.Graphics getComponentGraphics(java.awt.Graphics g)
Returns the graphics object used to paint this component. Configures the specified graphics object's foreground and font.

Parameters:
g - the original Graphics object
Returns:
a Graphics object configured for this component

paintComponent

protected void paintComponent(java.awt.Graphics g)
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).

Parameters:
g - the Graphics object to protect
See Also:
paint(java.awt.Graphics), ComponentUI

paintChildren

protected void paintChildren(java.awt.Graphics g)
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.

Parameters:
g - the Graphics context in which to paint
See Also:
paint(java.awt.Graphics), Container.paint(java.awt.Graphics)

paintBorder

protected void paintBorder(java.awt.Graphics g)
Paints the component's border.

Parameters:
g - the Graphics context in which to paint
See Also:
paint(java.awt.Graphics), setBorder(javax.swing.border.Border)

update

public void update(java.awt.Graphics g)
Calls paint. Doesn't clear the background but see ComponentUI.update, which is called by paintComponent.

Parameters:
g - the Graphics context in which to paint
See Also:
paint(java.awt.Graphics), paintComponent(java.awt.Graphics), ComponentUI

paint

public void paint(java.awt.Graphics g)
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.

Parameters:
g - the Graphics context in which to paint
See Also:
paintBorder(java.awt.Graphics), paintChildren(java.awt.Graphics), getComponentGraphics(java.awt.Graphics), repaint(long, int, int, int, int)

printAll

public void printAll(java.awt.Graphics g)
Invoke this method to print the component. This method invokes print on the component.

Parameters:
g - the Graphics context in which to paint
See Also:
print(java.awt.Graphics), printComponent(java.awt.Graphics), printBorder(java.awt.Graphics), printChildren(java.awt.Graphics)

print

public void print(java.awt.Graphics g)
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. 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.

Parameters:
g - the Graphics context in which to paint
See Also:
printComponent(java.awt.Graphics), printBorder(java.awt.Graphics), printChildren(java.awt.Graphics)

printComponent

protected void printComponent(java.awt.Graphics g)
This is invoked during a printing operation. This is implemented to invoke paintComponent on the component.

Parameters:
g - the Graphics context in which to paint
Since:
1.3
See Also:
print(java.awt.Graphics)

printChildren

protected void printChildren(java.awt.Graphics g)
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.

Parameters:
g - the Graphics context in which to paint
Since:
1.3
See Also:
print(java.awt.Graphics)

printBorder

protected void printBorder(java.awt.Graphics g)
Prints the component's border. This is implemented to invoke paintBorder on the component.

Parameters:
g - the Graphics context in which to paint
Since:
1.3
See Also:
print(java.awt.Graphics)

isPaintingTile

public boolean isPaintingTile()
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.

Returns:
true if the component is currently painting a tile, false otherwise

setRequestFocusEnabled

public void setRequestFocusEnabled(boolean requestFocusEnabled)
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.

Parameters:
requestFocusEnabled - Indicates if you want this JComponent to be focusable or not
See Also:
Focus Specification, Component.setFocusable(boolean)

isRequestFocusEnabled

public boolean isRequestFocusEnabled()
Returns true if this JComponent should get focus; otherwise returns false.

Returns:
true if this component should get focus, otherwise returns false
See Also:
setRequestFocusEnabled(boolean), Focus Specification, Component.isFocusable()

requestFocus

public void requestFocus()

requestFocus

public boolean requestFocus(boolean temporary)
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.

Refer to Component.requestFocus(boolean) for a complete description of this method.

Parameters:
temporary - boolean indicating if the focus change is temporary
Returns:
false if the focus change request is guaranteed to fail; true if it is likely to succeed
Since:
1.4
See Also:
Component.requestFocus(), Component.requestFocusInWindow(), Component.requestFocus(boolean), Component.requestFocusInWindow(boolean)

requestFocusInWindow

public boolean requestFocusInWindow()

requestFocusInWindow

protected boolean requestFocusInWindow(boolean temporary)
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.

Refer to Component.requestFocusInWindow(boolean) for a complete description of this method.

Parameters:
temporary - boolean indicating if the focus change is temporary
Returns:
false if the focus change request is guaranteed to fail; true if it is likely to succeed
Since:
1.4
See Also:
Component.requestFocus(), Component.requestFocusInWindow(), Component.requestFocus(boolean), Component.requestFocusInWindow(boolean)

setVerifyInputWhenFocusTarget

public void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. 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.

Parameters:
verifyInputWhenFocusTarget - value for the verifyInputWhenFocusTarget property
Since:
1.3
See Also:
InputVerifier, setInputVerifier(javax.swing.InputVerifier), getInputVerifier(), getVerifyInputWhenFocusTarget()

getVerifyInputWhenFocusTarget

public boolean getVerifyInputWhenFocusTarget()
Returns the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus.

Returns:
value of the verifyInputWhenFocusTarget property
Since:
1.3
See Also:
InputVerifier, setInputVerifier(javax.swing.InputVerifier), getInputVerifier(), setVerifyInputWhenFocusTarget(boolean)

setPreferredSize

public void setPreferredSize(Dimension preferredSize)
Sets the preferred size of this component. If preferredSize is null, the UI will be asked for the preferred size.


getPreferredSize

public Dimension getPreferredSize()
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:
the value of the preferredSize property
See Also:
setPreferredSize(java.awt.Dimension), ComponentUI

setMaximumSize

public void setMaximumSize(Dimension maximumSize)
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.

Parameters:
maximumSize - a Dimension containing the desired maximum allowable size
See Also:
getMaximumSize()

getMaximumSize

public Dimension getMaximumSize()
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:
the value of the maximumSize property
See Also:
setMaximumSize(java.awt.Dimension), ComponentUI

setMinimumSize

public void setMinimumSize(Dimension minimumSize)
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.

Parameters:
minimumSize - the new minimum size of this component
See Also:
getMinimumSize()

getMinimumSize

public Dimension getMinimumSize()
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.

Returns:
the value of the minimumSize property
See Also:
setMinimumSize(java.awt.Dimension), ComponentUI

isMinimumSizeSet

public boolean isMinimumSizeSet()
Returns true if the minimum size has been set to a non-null value otherwise returns false.

Returns:
true if minimumSize is non-null, false otherwise
Since:
1.3

isPreferredSizeSet

public boolean isPreferredSizeSet()
Returns true if the preferred size has been set to a non-null value otherwise returns false.

Returns:
true if preferredSize is non-null, false otherwise
Since:
1.3

isMaximumSizeSet

public boolean isMaximumSizeSet()
Returns true if the maximum size has been set to a non-null value otherwise returns false.

Returns:
true if maximumSize is non-null, false otherwise
Since:
1.3

contains

public boolean contains(int x,
                        int y)
Gives the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing.

Returns:
true if this component logically contains x,y
See Also:
Component.contains(int, int), ComponentUI

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 (such as 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

getBorder

public Border getBorder()
Returns the border of this component or null if no border is currently set.

This method is restricted in JSR-209

If the Border requested via the setBorder method is not supported by the implementation, this method will return an instance of the substitute Border that is being used instead.

Returns:
the border object for this component
See Also:
setBorder(javax.swing.border.Border)

getInsets

public java.awt.Insets getInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Returns:
the value of the insets property
See Also:
setBorder(javax.swing.border.Border)

getInsets

public java.awt.Insets getInsets(java.awt.Insets insets)
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.

Parameters:
insets - the Insets object, which can be reused
Returns:
the Insets object
See Also:
getInsets()

getAlignmentY

public float getAlignmentY()
Overrides Container.getAlignmentY to return the horizontal alignment.

Returns:
the value of the alignmentY property
See Also:
setAlignmentY(float), Component.getAlignmentY()

setAlignmentY

public void setAlignmentY(float alignmentY)
Sets the the horizontal alignment.

Parameters:
alignmentY - the new horizontal alignment
See Also:
getAlignmentY()

getAlignmentX

public float getAlignmentX()
Overrides Container.getAlignmentX to return the vertical alignment.

Returns:
the value of the alignmentX property
See Also:
setAlignmentX(float), Component.getAlignmentX()

setAlignmentX

public void setAlignmentX(float alignmentX)
Sets the the vertical alignment.

Parameters:
alignmentX - the new vertical alignment
See Also:
getAlignmentX()

setInputVerifier

public void setInputVerifier(InputVerifier inputVerifier)
Sets the input verifier for this component.

Parameters:
inputVerifier - the new input verifier
Since:
1.3
See Also:
InputVerifier

getInputVerifier

public InputVerifier getInputVerifier()
Returns the input verifier for this component.

Returns:
the inputVerifier property
Since:
1.3
See Also:
InputVerifier

getGraphics

public java.awt.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 operations on that object to draw on the component.

Returns:
this components graphics context

registerKeyboardAction

public void registerKeyboardAction(java.awt.event.ActionListener anAction,
                                   java.lang.String aCommand,
                                   KeyStroke aKeyStroke,
                                   int aCondition)
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:
   component.getInputMap().put(aKeyStroke, aCommand);
   component.getActionMap().put(aCommmand, anAction);
 
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:
anAction - the Action to be registered
aCommand - the command to be set in the delivered event
aKeyStroke - the KeyStroke to bind to the action
aCondition - the condition that needs to be met, see above
See Also:
KeyStroke

registerKeyboardAction

public void registerKeyboardAction(java.awt.event.ActionListener anAction,
                                   KeyStroke aKeyStroke,
                                   int aCondition)
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similiar behavior.


unregisterKeyboardAction

public void unregisterKeyboardAction(KeyStroke aKeyStroke)
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.

Unregisters a keyboard action. This will remove the binding from the ActionMap (if it exists) as well as the InputMaps.


getRegisteredKeyStrokes

public KeyStroke[] getRegisteredKeyStrokes()
Returns the KeyStrokes that will initiate registered actions.

Returns:
an array of KeyStroke objects
See Also:
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

getConditionForKeyStroke

public int getConditionForKeyStroke(KeyStroke aKeyStroke)
Returns the condition that determines whether a registered action occurs in response to the specified keystroke.

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

public java.awt.event.ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
Returns the object that will perform the action registered for a given keystroke.

Returns:
the ActionListener object invoked when the keystroke occurs

resetKeyboardActions

public void resetKeyboardActions()
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.


setInputMap

public final void setInputMap(int condition,
                              InputMap map)
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: 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.

Parameters:
condition - one of the values listed above
map - the InputMap to use for the given condition
Throws:
java.lang.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

getInputMap

public final InputMap getInputMap(int condition)
Returns the InputMap that is used during condition.

Parameters:
condition - one of WHEN_IN_FOCUSED_WINDOW, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Returns:
the InputMap for the specified condition
Since:
1.3

getInputMap

public final InputMap getInputMap()
Returns the InputMap that is used when the component has focus. This is convenience method for getInputMap(WHEN_FOCUSED).

Returns:
the InputMap used when the component has focus
Since:
JDK1.3

setActionMap

public final void setActionMap(ActionMap am)
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:
am - the new ActionMap
Since:
1.3

getActionMap

public final ActionMap getActionMap()
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 ActionMap containing the key/action bindings
Since:
1.3

setVisible

public void setVisible(boolean aFlag)
Makes the component visible or invisible. Overrides Component.setVisible.

Parameters:
aFlag - true to make the component visible; false to make it invisible

setEnabled

public void setEnabled(boolean enabled)
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.

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

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

Parameters:
enabled - true if this component should be enabled, false otherwise
See Also:
Component.isEnabled(), Component.isLightweight()

setForeground

public void setForeground(Color fg)
Sets the foreground color of this component.

This method is restricted in JSR-209

Though the color may be set on any component, its impact on the appearance of the component is subject to the component type (native implementation or Java programming language rendered implementation) and its visual representation.

Parameters:
fg - the desired foreground Color
See Also:
Component.getForeground()

setBackground

public void setBackground(Color bg)
Sets the background color of this component.

This method is restricted in JSR-209

Though the color may be set on any component, its impact on the appearance of the component is subject to the component type (native implementation or Java programming language rendered implementation) and its visual representation.

Parameters:
bg - the desired background Color
See Also:
Component.getBackground()

setFont

public void setFont(Font font)
Sets the font for this component.

Parameters:
font - the desired Font for this component
See Also:
Component.getFont()

getDefaultLocale

public static java.util.Locale getDefaultLocale()
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).

Returns:
the default Locale.
Since:
1.4
See Also:
setDefaultLocale(java.util.Locale), Component.getLocale(), Component.setLocale(java.util.Locale)

setDefaultLocale

public static void setDefaultLocale(java.util.Locale l)
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).

Parameters:
l - the desired default Locale for new components.
Since:
1.4
See Also:
getDefaultLocale(), Component.getLocale(), Component.setLocale(java.util.Locale)

processComponentKeyEvent

protected void processComponentKeyEvent(java.awt.event.KeyEvent e)
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.


processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e)
Overrides processKeyEvent to process events.


processKeyBinding

protected boolean processKeyBinding(KeyStroke ks,
                                    java.awt.event.KeyEvent e,
                                    int condition,
                                    boolean pressed)
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.

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
Since:
1.3

setToolTipText

public void setToolTipText(java.lang.String text)
Registers the text to display in a tool tip. The text displays when the cursor lingers over the component.

See How to Use Tool Tips in The Java Tutorial for further documentation.

Parameters:
text - the string to display; if the text is null, the tool tip is turned off for this component
See Also:
TOOL_TIP_TEXT_KEY

getToolTipText

public java.lang.String getToolTipText()
Returns the tooltip string that has been set with setToolTipText.

Returns:
the text of the tool tip
See Also:
TOOL_TIP_TEXT_KEY

scrollRectToVisible

public void scrollRectToVisible(Rectangle aRect)
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:
aRect - the visible Rectangle
See Also:
JViewport

setAutoscrolls

public void setAutoscrolls(boolean autoscrolls)
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:
 MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {
     public void mouseDragged(MouseEvent e) {
        Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
        ((JPanel)e.getSource()).scrollRectToVisible(r);
    }
 };
 myPanel.addMouseMotionListener(doScrollRectToVisible);
 
The default value of the autoScrolls property is false.

Parameters:
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
See Also:
getAutoscrolls(), JViewport, JScrollPane

getAutoscrolls

public boolean getAutoscrolls()
Gets the autoscrolls property.

Returns:
the value of the autoscrolls property
See Also:
JViewport, setAutoscrolls(boolean)

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.

Parameters:
e - the MouseEvent
See Also:
MouseEvent

getClientProperty

public final java.lang.Object getClientProperty(java.lang.Object key)
Returns the value of the property with the specified key. Only properties added with putClientProperty will return a non-null value.

Parameters:
key - the being queried
Returns:
the value of this property or null
See Also:
putClientProperty(java.lang.Object, java.lang.Object)

putClientProperty

public final void putClientProperty(java.lang.Object key,
                                    java.lang.Object value)
Adds an arbitrary key/value "client property" to this component.

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.

Parameters:
key - the new client property key
value - the new client property value; if null this method will remove the property
See Also:
getClientProperty(java.lang.Object), addPropertyChangeListener(java.beans.PropertyChangeListener)

reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Moves and resizes this component.

Parameters:
x - the new horizontal location
y - the new vertical location
w - the new width
h - the new height
See Also:
Component.setBounds(int, int, int, int)

getBounds

public Rectangle getBounds(Rectangle rv)
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.

Parameters:
rv - the return value, modified to the component's bounds
Returns:
rv; if rv is null return a newly created Rectangle with this component's bounds

getSize

public Dimension getSize(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.

Parameters:
rv - the return value, modified to the component's size
Returns:
rv

getLocation

public Point getLocation(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.

Parameters:
rv - the return value, modified to the component's location
Returns:
rv

getX

public int getX()
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.

Returns:
the current x coordinate of the component's origin

getY

public int getY()
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 current y coordinate of the component's origin

getWidth

public int getWidth()
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 current width of this component

getHeight

public int getHeight()
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.

Returns:
the current height of this component

isOpaque

public boolean isOpaque()
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.

Returns:
true if this component is completely opaque
See Also:
setOpaque(boolean)

setOpaque

public void setOpaque(boolean isOpaque)
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.

Parameters:
isOpaque - true if this component should be opaque
See Also:
isOpaque()

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.

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
See Also:
getVisibleRect()

getVisibleRect

public Rectangle getVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle:
 new Rectangle(0, 0, getWidth(), getHeight());
 
and all of its ancestors' visible rectangles.

Returns:
the visible rectangle

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
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:
 public void setFoo(int newValue) {
     int oldValue = foo;
     foo = newValue;
     firePropertyChange("foo", oldValue, newValue);
 }
 

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as an Object)
newValue - the new value of the property (as an Object)
See Also:
PropertyChangeSupport

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               byte oldValue,
                               byte newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a byte)
newValue - the new value of the property (as a byte)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               char oldValue,
                               char newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a char)
newValue - the new value of the property (as a char)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               short oldValue,
                               short newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a short)
newValue - the old value of the property (as a short)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               int oldValue,
                               int newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as an int)
newValue - the new value of the property (as an int)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               long oldValue,
                               long newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a long)
newValue - the new value of the property (as a long)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               float oldValue,
                               float newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a float)
newValue - the new value of the property (as a float)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               double oldValue,
                               double newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a double)
newValue - the new value of the property (as a double)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

firePropertyChange

public void firePropertyChange(java.lang.String propertyName,
                               boolean oldValue,
                               boolean newValue)
Reports a bound property change.

Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property (as a boolean)
newValue - the new value of the property (as a boolean)
See Also:
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
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.

Parameters:
listener - the PropertyChangeListener to be added

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

If listener is null, no exception is thrown and no action is performed.

Parameters:
propertyName - the name of the property to listen on
listener - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - the PropertyChangeListener to be removed

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener for a specific property. If listener is null, no exception is thrown and no action is performed.

Parameters:
propertyName - the name of the property that was listened on
listener - the PropertyChangeListener to be removed

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the PropertyChangeListeners added to this Component with addPropertyChangeListener().

Returns:
all of the PropertyChangeListeners added or an empty array if no listeners have been added
Since:
1.4
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener), removePropertyChangeListener(java.beans.PropertyChangeListener), getPropertyChangeListeners(java.lang.String), PropertyChangeSupport.getPropertyChangeListeners()

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Returns an array of all the listeners which have been associated with the named property.

Returns:
all of the PropertyChangeListeners associated with the named property or an empty array if no listeners have been added
Since:
1.4
See Also:
getPropertyChangeListeners()

fireVetoableChange

protected void fireVetoableChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
                           throws java.beans.PropertyVetoException
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:
java.beans.PropertyVetoException - when the attempt to set the property is vetoed by the component

addVetoableChangeListener

public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list. The listener is registered for all properties.

Parameters:
listener - the VetoableChangeListener to be added

removeVetoableChangeListener

public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list. This removes a VetoableChangeListener that was registered for all properties.

Parameters:
listener - the VetoableChangeListener to be removed

getVetoableChangeListeners

public java.beans.VetoableChangeListener[] getVetoableChangeListeners()
Returns an array of all the vetoable change listeners registered on this component.

Returns:
all of the component's VetoableChangeListeners or an empty array if no vetoable change listeners are currently registered
Since:
1.4
See Also:
addVetoableChangeListener(java.beans.VetoableChangeListener), removeVetoableChangeListener(java.beans.VetoableChangeListener)

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.

Parameters:
listener - the AncestorListener to be removed
See Also:
addAncestorListener(javax.swing.event.AncestorListener)

getAncestorListeners

public AncestorListener[] getAncestorListeners()
Returns an array of all the ancestor listeners registered on this component.

Returns:
all of the component's AncestorListeners or an empty array if no ancestor listeners are currently registered
Since:
1.4
See Also:
addAncestorListener(javax.swing.event.AncestorListener), removeAncestorListener(javax.swing.event.AncestorListener)

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this JComponent. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a JComponent c for its mouse listeners with the following code:

MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this component, or an empty array if no such listeners have been added
Throws:
java.lang.ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since:
1.3
See Also:
getVetoableChangeListeners(), getAncestorListeners()

addNotify

public void addNotify()
Notifies 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.

See Also:
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

removeNotify

public void removeNotify()
Notifies 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.

See Also:
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int width,
                    int height)
Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.

Parameters:
tm - this parameter is not used
x - the x value of the dirty region
y - the y value of the dirty region
width - the width of the dirty region
height - the height of the dirty region
See Also:
Component.isShowing(), RepaintManager#addDirtyRegion

repaint

public void repaint(Rectangle r)
Adds the specified region to the dirty region list if the component is showing. The component will be repainted after all of the currently pending events have been dispatched.

Parameters:
r - a Rectangle containing the dirty region
See Also:
Component.isShowing(), RepaintManager#addDirtyRegion

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.

See Also:
Component.invalidate(), Container.validate(), isValidateRoot(), RepaintManager#addInvalidComponent

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.

Returns:
always returns false
See Also:
revalidate(), Component.invalidate(), Container.validate()

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

Parameters:
x - the x value of the region to be painted
y - the y value of the region to be painted
w - the width of the region to be painted
h - the height of the region to be painted
See Also:
repaint(long, int, int, int, int)

paintImmediately

public final void paintImmediately(Rectangle r)
Paints the specified region now.

Parameters:
r - a Rectangle containing the region to be painted

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.

Parameters:
aFlag - if true, set this component to be double buffered

isDoubleBuffered

public boolean isDoubleBuffered()
Returns whether this component should use a buffer to paint.

Returns:
true if this component is double buffered, otherwise false

paramString

protected java.lang.String 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.

Returns:
a string representation of this JComponent

JSR-209 (Final Approval Ballot)

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 209 specification.