java.awt

Class Component

public abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable

The root of all evil. All graphical representations are subclasses of this giant class, which is designed for screen display and user interaction. This class can be extended directly to build a lightweight component (one not associated with a native window); lightweight components must reside inside a heavyweight window.

This class is Serializable, which has some big implications. A user can save the state of all graphical components in one VM, and reload them in another. Note that this class will only save Serializable listeners, and ignore the rest, without causing any serialization exceptions. However, by making a listener serializable, and adding it to another element, you link in that entire element to the state of this component. To get around this, use the idiom shown in the example below - make listeners non-serializable in inner classes, rather than using this object itself as the listener, if external objects do not need to save the state of this object.

 import java.awt.*;
 import java.awt.event.*;
 import java.io.Serializable;
 class MyApp implements Serializable
 {
   BigObjectThatShouldNotBeSerializedWithAButton bigOne;
   // Serializing aButton will not suck in an instance of MyApp, with its
   // accompanying field bigOne.
   Button aButton = new Button();
   class MyActionListener implements ActionListener
   {
     public void actionPerformed(ActionEvent e)
     {
       System.out.println("Hello There");
     }
   }
   MyApp()
   {
     aButton.addActionListener(new MyActionListener());
   }
 }
 

Status: Incomplete. The event dispatch mechanism is implemented. All other methods defined in the J2SE 1.3 API javadoc exist, but are mostly incomplete or only stubs; except for methods relating to the Drag and Drop, Input Method, and Accessibility frameworks: These methods are present but commented out.

Since: 1.0

UNKNOWN: still missing 1.4 support

Nested Class Summary
protected abstract classComponent.AccessibleAWTComponent
This class provides accessibility support for subclasses of container.
protected classComponent.BltBufferStrategy
This class provides support for blitting offscreen surfaces to a component.
protected classComponent.FlipBufferStrategy
This class provides support for flipping component buffers.
Field Summary
static floatBOTTOM_ALIGNMENT
Constant returned by the getAlignmentY method to indicate that the component wishes to be aligned to the bottom relative to other components.
static floatCENTER_ALIGNMENT
Constant returned by the getAlignmentY and getAlignmentX methods to indicate that the component wishes to be aligned to the center relative to other components.
static floatLEFT_ALIGNMENT
Constant returned by the getAlignmentX method to indicate that the component wishes to be aligned to the left relative to other components.
static floatRIGHT_ALIGNMENT
Constant returned by the getAlignmentX method to indicate that the component wishes to be aligned to the right relative to other components.
static floatTOP_ALIGNMENT
Constant returned by the getAlignmentY method to indicate that the component wishes to be aligned to the top relative to other components.
Constructor Summary
protected Component()
Default constructor for subclasses.
Method Summary
booleanaction(Event evt, Object what)
AWT 1.0 ACTION_EVENT event handler.
voidadd(PopupMenu popup)
Adds the specified popup menu to this component.
voidaddComponentListener(ComponentListener listener)
Adds the specified listener to this component.
voidaddFocusListener(FocusListener listener)
Adds the specified listener to this component.
voidaddHierarchyBoundsListener(HierarchyBoundsListener listener)
Adds the specified listener to this component.
voidaddHierarchyListener(HierarchyListener listener)
Adds the specified listener to this component.
voidaddInputMethodListener(InputMethodListener listener)
Adds the specified listener to this component.
voidaddKeyListener(KeyListener listener)
Adds the specified listener to this component.
voidaddMouseListener(MouseListener listener)
Adds the specified listener to this component.
voidaddMouseMotionListener(MouseMotionListener listener)
Adds the specified listener to this component.
voidaddMouseWheelListener(MouseWheelListener listener)
Adds the specified listener to this component.
voidaddNotify()
Called when the parent of this Component is made visible or when the Component is added to an already visible Container and needs to be shown.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds the specified property listener to this component.
voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Adds the specified property listener to this component.
voidapplyComponentOrientation(ComponentOrientation o)
Sets the text layout orientation of this component.
booleanareFocusTraversalKeysSet(int id)
Tests whether the focus traversal keys for a given action are explicitly set or inherited.
Rectanglebounds()
Returns a bounding rectangle for this component.
intcheckImage(Image image, ImageObserver observer)
Returns the status of the loading of the specified image.
intcheckImage(Image image, int width, int height, ImageObserver observer)
Returns the status of the loading of the specified image.
protected AWTEventcoalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
This is called by the EventQueue if two events with the same event id and owner component are queued.
booleancontains(int x, int y)
Tests whether or not the specified point is contained within this component.
booleancontains(Point p)
Tests whether or not the specified point is contained within this component.
ImagecreateImage(ImageProducer producer)
Creates an image from the specified producer.
ImagecreateImage(int width, int height)
Creates an image with the specified width and height for use in double buffering.
VolatileImagecreateVolatileImage(int width, int height)
Creates an image with the specified width and height for use in double buffering.
VolatileImagecreateVolatileImage(int width, int height, ImageCapabilities caps)
Creates an image with the specified width and height for use in double buffering.
voiddeliverEvent(Event e)
AWT 1.0 event delivery.
voiddisable()
Disables this component.
protected voiddisableEvents(long eventsToDisable)
Disables the specified events.
voiddispatchEvent(AWTEvent e)
Forwards AWT events to processEvent() if:
  • Events have been enabled for this type of event via enableEvents()
  • ,
  • There is at least one registered listener for this type of event
voiddoLayout()
Calls the layout manager to re-layout the component.
voidenable()
Enables this component.
voidenable(boolean enabled)
Enables or disables this component.
protected voidenableEvents(long eventsToEnable)
Enables the specified events.
voidenableInputMethods(boolean enable)
Enables or disables input method support for this component.
protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)
Report a change in a bound property to any registered property listeners.
protected voidfirePropertyChange(String propertyName, boolean oldValue, boolean newValue)
Report a change in a bound property to any registered property listeners.
protected voidfirePropertyChange(String propertyName, int oldValue, int newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, byte oldValue, byte newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, char oldValue, char newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, short oldValue, short newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, long oldValue, long newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, float oldValue, float newValue)
Report a change in a bound property to any registered property listeners.
voidfirePropertyChange(String propertyName, double oldValue, double newValue)
Report a change in a bound property to any registered property listeners.
AccessibleContextgetAccessibleContext()
Returns the accessibility framework context of this class.
floatgetAlignmentX()
Returns the preferred horizontal alignment of this component.
floatgetAlignmentY()
Returns the preferred vertical alignment of this component.
ColorgetBackground()
Returns this component's background color.
RectanglegetBounds()
Returns a bounding rectangle for this component.
RectanglegetBounds(Rectangle r)
Returns the bounds of this component.
ColorModelgetColorModel()
Returns the color model of the device this componet is displayed on.
ComponentgetComponentAt(int x, int y)
Returns the component occupying the position (x,y).
ComponentgetComponentAt(Point p)
Returns the component occupying the position (x,y).
ComponentListener[]getComponentListeners()
Returns an array of all specified listeners registered on this component.
ComponentOrientationgetComponentOrientation()
Determines the text layout orientation used by this component.
CursorgetCursor()
Returns the cursor for this component.
DropTargetgetDropTarget()
Gets the associated drag-and-drop target, if there is one.
ContainergetFocusCycleRootAncestor()
Returns the root container that owns the focus cycle where this component resides.
FocusListener[]getFocusListeners()
Returns an array of all specified listeners registered on this component.
Set<AWTKeyStroke>getFocusTraversalKeys(int id)
Returns the set of keys for a given focus traversal action, as defined in setFocusTraversalKeys.
booleangetFocusTraversalKeysEnabled()
Check whether or not focus traversal keys are enabled on this Component.
FontgetFont()
Returns the font in use for this component.
FontMetricsgetFontMetrics(Font font)
Returns the font metrics for the specified font in this component.
ColorgetForeground()
Returns this component's foreground color.
GraphicsgetGraphics()
Returns a graphics object for this component.
GraphicsConfigurationgetGraphicsConfiguration()
Returns the graphics configuration of this component, if there is one.
intgetHeight()
Gets the height of the component.
HierarchyBoundsListener[]getHierarchyBoundsListeners()
Returns an array of all specified listeners registered on this component.
HierarchyListener[]getHierarchyListeners()
Returns an array of all specified listeners registered on this component.
booleangetIgnoreRepaint()
Test whether paint events from the operating system are ignored.
InputContextgetInputContext()
Gets the input context of this component, which is inherited from the parent unless this is overridden.
InputMethodListener[]getInputMethodListeners()
Returns an array of all specified listeners registered on this component.
InputMethodRequestsgetInputMethodRequests()
Returns the input method request handler, for subclasses which support on-the-spot text input.
KeyListener[]getKeyListeners()
Returns an array of all specified listeners registered on this component.
<T extends EventListener> T[]getListeners(Class<T> listenerType)
Returns all registered {@link EventListener}s of the given listenerType.
LocalegetLocale()
Returns the locale for this component.
PointgetLocation()
Returns the location of this component's top left corner relative to its parent component.
PointgetLocation(Point p)
Returns the location of this component.
PointgetLocationOnScreen()
Returns the location of this component's top left corner in screen coordinates.
DimensiongetMaximumSize()
Returns the component's maximum size.
DimensiongetMinimumSize()
Returns the component's minimum size.
MouseListener[]getMouseListeners()
Returns an array of all specified listeners registered on this component.
MouseMotionListener[]getMouseMotionListeners()
Returns an array of all specified listeners registered on this component.
MouseWheelListener[]getMouseWheelListeners()
Returns an array of all specified listeners registered on this component.
StringgetName()
Returns the name of this component.
ContainergetParent()
Returns the parent of this component.
ComponentPeergetPeer()
Returns the native windowing system peer for this component.
DimensiongetPreferredSize()
Returns the component's preferred size.
PropertyChangeListener[]getPropertyChangeListeners()
Returns an array of all specified listeners registered on this component.
PropertyChangeListener[]getPropertyChangeListeners(String property)
Returns an array of all specified listeners on the named property that are registered on this component.
DimensiongetSize()
Returns the size of this object.
DimensiongetSize(Dimension d)
Returns the size of this component.
ToolkitgetToolkit()
Returns the toolkit in use for this component.
ObjectgetTreeLock()
Returns the object used for synchronization locks on this component when performing tree and layout functions.
intgetWidth()
Gets the width of the component.
intgetX()
Gets the x coordinate of the upper left corner.
intgetY()
Gets the y coordinate of the upper left corner.
booleangotFocus(Event evt, Object what)
AWT 1.0 GOT_FOCUS event handler.
booleanhandleEvent(Event evt)
AWT 1.0 event handler.
booleanhasFocus()
Tests if this component is the focus owner.
voidhide()
Hides this component so that it is no longer shown on the screen.
booleanimageUpdate(Image img, int flags, int x, int y, int w, int h)
Called when an image has changed so that this component is repainted.
booleaninside(int x, int y)
Tests whether or not the specified point is contained within this component.
voidinvalidate()
Invalidates this component and all of its parent components.
booleanisBackgroundSet()
Tests if the background was explicitly set, or just inherited from the parent.
booleanisCursorSet()
Tests if the cursor was explicitly set, or just inherited from the parent.
booleanisDisplayable()
Tests if the component is displayable.
booleanisDoubleBuffered()
Checks if this image is painted to an offscreen image buffer that is later copied to screen (double buffering reduces flicker).
booleanisEnabled()
Tests whether or not this component is enabled.
booleanisFocusable()
Tests if this component can receive focus.
booleanisFocusCycleRoot(Container c)
Tests if the container is the ancestor of the focus cycle that this component belongs to.
booleanisFocusOwner()
Tests if this component is the focus owner.
booleanisFocusTraversable()
Tests whether or not this component is in the group that can be traversed using the keyboard traversal mechanism (such as the TAB key).
booleanisFontSet()
Tests if the font was explicitly set, or just inherited from the parent.
booleanisForegroundSet()
Tests if the foreground was explicitly set, or just inherited from the parent.
booleanisLightweight()
Return whether the component is lightweight.
booleanisMaximumSizeSet()
Returns true if the current maximum size is not null and was set by a call to {@link #setMaximumSize(Dimension)}, otherwise returns false.
booleanisMinimumSizeSet()
Returns true if the current minimum size is not null and was set by a call to {@link #setMinimumSize(Dimension)}, otherwise returns false.
booleanisOpaque()
Tests if this component is opaque.
booleanisPreferredSizeSet()
Returns true if the current preferred size is not null and was set by a call to {@link #setPreferredSize(Dimension)}, otherwise returns false.
booleanisShowing()
Tests whether or not this component is actually being shown on the screen.
booleanisValid()
Tests whether or not this component is valid.
booleanisVisible()
Tests whether or not this component is visible.
booleankeyDown(Event evt, int key)
AWT 1.0 KEY_PRESS and KEY_ACTION event handler.
booleankeyUp(Event evt, int key)
AWT 1.0 KEY_RELEASE and KEY_ACTION_RELEASE event handler.
voidlayout()
Calls the layout manager to re-layout the component.
voidlist()
Prints a listing of this component to System.out.
voidlist(PrintStream out)
Prints a listing of this component to the specified print stream.
voidlist(PrintStream out, int indent)
Prints a listing of this component to the specified print stream, starting at the specified indentation point.
voidlist(PrintWriter out)
Prints a listing of this component to the specified print writer.
voidlist(PrintWriter out, int indent)
Prints a listing of this component to the specified print writer, starting at the specified indentation point.
Componentlocate(int x, int y)
Returns the component occupying the position (x,y).
Pointlocation()
Returns the location of this component's top left corner relative to its parent component.
booleanlostFocus(Event evt, Object what)
AWT 1.0 LOST_FOCUS event handler.
DimensionminimumSize()
Returns the component's minimum size.
booleanmouseDown(Event evt, int x, int y)
AWT 1.0 MOUSE_DOWN event handler.
booleanmouseDrag(Event evt, int x, int y)
AWT 1.0 MOUSE_DRAG event handler.
booleanmouseEnter(Event evt, int x, int y)
AWT 1.0 MOUSE_ENTER event handler.
booleanmouseExit(Event evt, int x, int y)
AWT 1.0 MOUSE_EXIT event handler.
booleanmouseMove(Event evt, int x, int y)
AWT 1.0 MOUSE_MOVE event handler.
booleanmouseUp(Event evt, int x, int y)
AWT 1.0 MOUSE_UP event handler.
voidmove(int x, int y)
Moves this component to the specified location, relative to the parent's coordinates.
voidnextFocus()
AWT 1.0 focus event processor.
voidpaint(Graphics g)
Paints this component on the screen.
voidpaintAll(Graphics g)
Paints this entire component, including any sub-components.
protected StringparamString()
Returns a debugging string representing this component.
booleanpostEvent(Event e)
AWT 1.0 event handler.
DimensionpreferredSize()
Returns the component's preferred size.
booleanprepareImage(Image image, ImageObserver observer)
Prepares the specified image for rendering on this component.
booleanprepareImage(Image image, int width, int height, ImageObserver observer)
Prepares the specified image for rendering on this component at the specified scaled width and height
voidprint(Graphics g)
Prints this component.
voidprintAll(Graphics g)
Prints this component, including all sub-components.
protected voidprocessComponentEvent(ComponentEvent e)
Called when a component event is dispatched and component events are enabled.
protected voidprocessEvent(AWTEvent e)
Processes the specified event.
protected voidprocessFocusEvent(FocusEvent e)
Called when a focus event is dispatched and component events are enabled.
protected voidprocessHierarchyBoundsEvent(HierarchyEvent e)
Called when a hierarchy bounds event is dispatched and component events are enabled.
protected voidprocessHierarchyEvent(HierarchyEvent e)
Called when a hierarchy change event is dispatched and component events are enabled.
protected voidprocessInputMethodEvent(InputMethodEvent e)
Called when an input method event is dispatched and component events are enabled.
protected voidprocessKeyEvent(KeyEvent e)
Called when a key event is dispatched and component events are enabled.
protected voidprocessMouseEvent(MouseEvent e)
Called when a regular mouse event is dispatched and component events are enabled.
protected voidprocessMouseMotionEvent(MouseEvent e)
Called when a mouse motion event is dispatched and component events are enabled.
protected voidprocessMouseWheelEvent(MouseWheelEvent e)
Called when a mouse wheel event is dispatched and component events are enabled.
voidremove(MenuComponent popup)
Removes the specified popup menu from this component.
voidremoveComponentListener(ComponentListener listener)
Removes the specified listener from the component.
voidremoveFocusListener(FocusListener listener)
Removes the specified listener from the component.
voidremoveHierarchyBoundsListener(HierarchyBoundsListener listener)
Removes the specified listener from the component.
voidremoveHierarchyListener(HierarchyListener listener)
Removes the specified listener from the component.
voidremoveInputMethodListener(InputMethodListener listener)
Removes the specified listener from the component.
voidremoveKeyListener(KeyListener listener)
Removes the specified listener from the component.
voidremoveMouseListener(MouseListener listener)
Removes the specified listener from the component.
voidremoveMouseMotionListener(MouseMotionListener listener)
Removes the specified listener from the component.
voidremoveMouseWheelListener(MouseWheelListener listener)
Removes the specified listener from the component.
voidremoveNotify()
Called to inform this component is has been removed from its container.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Removes the specified property listener from the component.
voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener)
Removes the specified property listener on a particular property from the component.
voidrepaint()
Repaint this entire component.
voidrepaint(long tm)
Repaint this entire component.
voidrepaint(int x, int y, int w, int h)
Repaints the specified rectangular region within this component.
voidrepaint(long tm, int x, int y, int width, int height)
Repaints the specified rectangular region within this component.
voidrequestFocus()
Request that this Component be given the keyboard input focus and that its top-level ancestor become the focused Window.
protected booleanrequestFocus(boolean temporary)
Request that this Component be given the keyboard input focus and that its top-level ancestor become the focused Window.
booleanrequestFocusInWindow()
Request that this component be given the keyboard input focus, if its top-level ancestor is the currently focused Window.
protected booleanrequestFocusInWindow(boolean temporary)
Request that this component be given the keyboard input focus, if its top-level ancestor is the currently focused Window.
voidreshape(int x, int y, int width, int height)
Sets the bounding rectangle for this component to the specified values.
voidresize(int width, int height)
Sets the size of this component to the specified value.
voidresize(Dimension d)
Sets the size of this component to the specified value.
voidsetBackground(Color c)
Sets this component's background color to the specified color.
voidsetBounds(int x, int y, int w, int h)
Sets the bounding rectangle for this component to the specified values.
voidsetBounds(Rectangle r)
Sets the bounding rectangle for this component to the specified rectangle.
voidsetComponentOrientation(ComponentOrientation o)
Sets the text layout orientation of this component.
voidsetCursor(Cursor cursor)
Sets the cursor for this component to the specified cursor.
voidsetDropTarget(DropTarget dt)
Set the associated drag-and-drop target, which receives events when this is enabled.
voidsetEnabled(boolean enabled)
Enables or disables this component.
voidsetFocusable(boolean focusable)
Specify whether this component can receive focus.
voidsetFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
Sets the focus traversal keys for one of the three focus traversal directions supported by Components: {@link KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS}, {@link KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS}, or {@link KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS}.
voidsetFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
Enable or disable focus traversal keys on this Component.
voidsetFont(Font f)
Sets the font for this component to the specified font.
voidsetForeground(Color c)
Sets this component's foreground color to the specified color.
voidsetIgnoreRepaint(boolean ignoreRepaint)
Sets whether paint messages delivered by the operating system should be ignored.
voidsetLocale(Locale newLocale)
Sets the locale for this component to the specified locale.
voidsetLocation(int x, int y)
Moves this component to the specified location, relative to the parent's coordinates.
voidsetLocation(Point p)
Moves this component to the specified location, relative to the parent's coordinates.
voidsetMaximumSize(Dimension size)
Sets the maximum size that will be returned by {@link #getMaximumSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'maximumSize') to all registered listeners.
voidsetMinimumSize(Dimension size)
Sets the minimum size that will be returned by {@link #getMinimumSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'minimumSize') to all registered listeners.
voidsetName(String name)
Sets the name of this component to the specified name (this is a bound property with the name 'name').
voidsetPreferredSize(Dimension size)
Sets the preferred size that will be returned by {@link #getPreferredSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'preferredSize') to all registered listeners.
voidsetSize(int width, int height)
Sets the size of this component to the specified width and height.
voidsetSize(Dimension d)
Sets the size of this component to the specified value.
voidsetVisible(boolean visible)
Makes this component visible or invisible.
voidshow()
Makes this component visible on the screen.
voidshow(boolean visible)
Makes this component visible or invisible.
Dimensionsize()
Returns the size of this object.
StringtoString()
Returns a string representation of this component.
voidtransferFocus()
Transfers focus to the next component in the focus traversal order, as though this were the current focus owner.
voidtransferFocusBackward()
Transfers focus to the previous component in the focus traversal order, as though this were the current focus owner.
voidtransferFocusUpCycle()
Transfers focus to the focus cycle root of this component.
voidupdate(Graphics g)
Updates this component.
voidvalidate()
Called to ensure that the layout for this component is valid.

Field Detail

BOTTOM_ALIGNMENT

public static final float BOTTOM_ALIGNMENT
Constant returned by the getAlignmentY method to indicate that the component wishes to be aligned to the bottom relative to other components.

See Also: getAlignmentY

CENTER_ALIGNMENT

public static final float CENTER_ALIGNMENT
Constant returned by the getAlignmentY and getAlignmentX methods to indicate that the component wishes to be aligned to the center relative to other components.

See Also: getAlignmentX getAlignmentY

LEFT_ALIGNMENT

public static final float LEFT_ALIGNMENT
Constant returned by the getAlignmentX method to indicate that the component wishes to be aligned to the left relative to other components.

See Also: getAlignmentX

RIGHT_ALIGNMENT

public static final float RIGHT_ALIGNMENT
Constant returned by the getAlignmentX method to indicate that the component wishes to be aligned to the right relative to other components.

See Also: getAlignmentX

TOP_ALIGNMENT

public static final float TOP_ALIGNMENT
Constant returned by the getAlignmentY method to indicate that the component wishes to be aligned to the top relative to other components.

See Also: getAlignmentY

Constructor Detail

Component

protected Component()
Default constructor for subclasses. When Component is extended directly, it forms a lightweight component that must be hosted in an opaque native container higher in the tree.

Method Detail

action

public boolean action(Event evt, Object what)

Deprecated: in classes which support actions, use processActionEvent(ActionEvent) instead

AWT 1.0 ACTION_EVENT event handler. This method is meant to be overridden by components providing their own action event handler. The default implementation simply returns false.

Parameters: evt the event to handle what the object acted on, ignored

Returns: false

add

public void add(PopupMenu popup)
Adds the specified popup menu to this component.

Parameters: popup the popup menu to be added

Since: 1.1

See Also:

addComponentListener

public void addComponentListener(ComponentListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.1

See Also: ComponentEvent removeComponentListener getComponentListeners

addFocusListener

public void addFocusListener(FocusListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.1

See Also: FocusEvent removeFocusListener getFocusListeners

addHierarchyBoundsListener

public void addHierarchyBoundsListener(HierarchyBoundsListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.3

See Also: HierarchyEvent removeHierarchyBoundsListener getHierarchyBoundsListeners

addHierarchyListener

public void addHierarchyListener(HierarchyListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.3

See Also: HierarchyEvent removeHierarchyListener getHierarchyListeners

addInputMethodListener

public void addInputMethodListener(InputMethodListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.2

See Also: InputMethodEvent removeInputMethodListener getInputMethodListeners getInputMethodRequests

addKeyListener

public void addKeyListener(KeyListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.1

See Also: KeyEvent removeKeyListener getKeyListeners

addMouseListener

public void addMouseListener(MouseListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.1

See Also: MouseEvent removeMouseListener getMouseListeners

addMouseMotionListener

public void addMouseMotionListener(MouseMotionListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.1

See Also: MouseEvent removeMouseMotionListener getMouseMotionListeners

addMouseWheelListener

public void addMouseWheelListener(MouseWheelListener listener)
Adds the specified listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice.

Parameters: listener the new listener to add

Since: 1.4

See Also: MouseEvent MouseWheelEvent removeMouseWheelListener getMouseWheelListeners

addNotify

public void addNotify()
Called when the parent of this Component is made visible or when the Component is added to an already visible Container and needs to be shown. A native peer - if any - is created at this time. This method is called automatically by the AWT system and should not be called by user level code.

See Also: isDisplayable removeNotify

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds the specified property listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice. The property listener ignores inherited properties. Recognized properties include:

Parameters: listener the new listener to add

Since: 1.1

See Also: removePropertyChangeListener getPropertyChangeListeners Component

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Adds the specified property listener to this component. This is harmless if the listener is null, but if the listener has already been registered, it will now be registered twice. The property listener ignores inherited properties. The listener is keyed to a single property. Recognized properties include:

Parameters: propertyName the property name to filter on listener the new listener to add

Since: 1.1

See Also: Component getPropertyChangeListeners addPropertyChangeListener

applyComponentOrientation

public void applyComponentOrientation(ComponentOrientation o)
Sets the text layout orientation of this component. New components default to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects the entire hierarchy, while {@link #setComponentOrientation(ComponentOrientation)} affects only the current component.

Parameters: o the new orientation

Throws: NullPointerException if o is null

Since: 1.4

See Also: getComponentOrientation

areFocusTraversalKeysSet

public boolean areFocusTraversalKeysSet(int id)
Tests whether the focus traversal keys for a given action are explicitly set or inherited.

Parameters: id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or UP_CYCLE_TRAVERSAL_KEYS

Returns: true if that set is explicitly specified

Throws: IllegalArgumentException if id is invalid

Since: 1.4

See Also: Component FORWARD_TRAVERSAL_KEYS BACKWARD_TRAVERSAL_KEYS UP_CYCLE_TRAVERSAL_KEYS

bounds

public Rectangle bounds()

Deprecated: use {@link #getBounds()} instead

Returns a bounding rectangle for this component. Note that the returned rectange is relative to this component's parent, not to the screen.

Returns: the bounding rectangle for this component

checkImage

public int checkImage(Image image, ImageObserver observer)
Returns the status of the loading of the specified image. The value returned will be those flags defined in ImageObserver.

Parameters: image the image to check on observer the observer to notify of image loading progress

Returns: the image observer flags indicating the status of the load

Throws: NullPointerException if image is null

See Also: Component Toolkit

checkImage

public int checkImage(Image image, int width, int height, ImageObserver observer)
Returns the status of the loading of the specified image. The value returned will be those flags defined in ImageObserver.

Parameters: image the image to check on width the scaled image width height the scaled image height observer the observer to notify of image loading progress

Returns: the image observer flags indicating the status of the load

See Also: Component Toolkit

coalesceEvents

protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
This is called by the EventQueue if two events with the same event id and owner component are queued. Returns a new combined event, or null if no combining is done. The coelesced events are currently mouse moves (intermediate ones are discarded) and paint events (a merged paint is created in place of the two events).

Parameters: existingEvent the event on the queue newEvent the new event that might be entered on the queue

Returns: null if both events are kept, or the replacement coelesced event

contains

public boolean contains(int x, int y)
Tests whether or not the specified point is contained within this component. Coordinates are relative to this component.

Parameters: x the X coordinate of the point to test y the Y coordinate of the point to test

Returns: true if the point is within this component

See Also: Component

contains

public boolean contains(Point p)
Tests whether or not the specified point is contained within this component. Coordinates are relative to this component.

Parameters: p the point to test

Returns: true if the point is within this component

Throws: NullPointerException if p is null

Since: 1.1

See Also: getComponentAt

createImage

public Image createImage(ImageProducer producer)
Creates an image from the specified producer.

Parameters: producer the image procedure to create the image from

Returns: the resulting image

createImage

public Image createImage(int width, int height)
Creates an image with the specified width and height for use in double buffering. Headless environments do not support images.

Parameters: width the width of the image height the height of the image

Returns: the requested image, or null if it is not supported

createVolatileImage

public VolatileImage createVolatileImage(int width, int height)
Creates an image with the specified width and height for use in double buffering. Headless environments do not support images.

Parameters: width the width of the image height the height of the image

Returns: the requested image, or null if it is not supported

Since: 1.4

createVolatileImage

public VolatileImage createVolatileImage(int width, int height, ImageCapabilities caps)
Creates an image with the specified width and height for use in double buffering. Headless environments do not support images. The image will support the specified capabilities.

Parameters: width the width of the image height the height of the image caps the requested capabilities

Returns: the requested image, or null if it is not supported

Throws: AWTException if a buffer with the capabilities cannot be created

Since: 1.4

deliverEvent

public void deliverEvent(Event e)

Deprecated: use {@link #dispatchEvent (AWTEvent)} instead

AWT 1.0 event delivery. Deliver an AWT 1.0 event to this Component. This method simply calls {@link #postEvent}.

Parameters: e the event to deliver

disable

public void disable()

Deprecated: use {@link #setEnabled(boolean)} instead

Disables this component.

disableEvents

protected final void disableEvents(long eventsToDisable)
Disables the specified events. The events to disable are specified by OR-ing together the desired masks from AWTEvent.

Parameters: eventsToDisable the desired events to disable

Since: 1.1

See Also: Component

dispatchEvent

public final void dispatchEvent(AWTEvent e)
Forwards AWT events to processEvent() if:

Parameters: e the event to dispatch

doLayout

public void doLayout()
Calls the layout manager to re-layout the component. This is called during validation of a container in most cases.

See Also: validate LayoutManager

enable

public void enable()

Deprecated: use {@link #setEnabled(boolean)} instead

Enables this component.

enable

public void enable(boolean enabled)

Deprecated: use {@link #setEnabled(boolean)} instead

Enables or disables this component.

Parameters: enabled true to enable this component

enableEvents

protected final void enableEvents(long eventsToEnable)
Enables the specified events. The events to enable are specified by OR-ing together the desired masks from AWTEvent.

Events are enabled by default when a listener is attached to the component for that event type. This method can be used by subclasses to ensure the delivery of a specified event regardless of whether or not a listener is attached.

Parameters: eventsToEnable the desired events to enable

Since: 1.1

See Also: processEvent Component AWTEvent

enableInputMethods

public void enableInputMethods(boolean enable)
Enables or disables input method support for this component. By default, components have this enabled. Input methods are given the opportunity to process key events before this component and its listeners.

Parameters: enable true to enable input method processing

Since: 1.2

See Also: processKeyEvent

firePropertyChange

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

firePropertyChange

protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

firePropertyChange

protected void firePropertyChange(String propertyName, int oldValue, int newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

firePropertyChange

public void firePropertyChange(String propertyName, byte oldValue, byte newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

firePropertyChange

public void firePropertyChange(String propertyName, char oldValue, char newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

firePropertyChange

public void firePropertyChange(String propertyName, short oldValue, short newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

firePropertyChange

public void firePropertyChange(String propertyName, long oldValue, long newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

firePropertyChange

public void firePropertyChange(String propertyName, float oldValue, float newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

firePropertyChange

public void firePropertyChange(String propertyName, double oldValue, double newValue)
Report a change in a bound property to any registered property listeners.

Parameters: propertyName the property that changed oldValue the old property value newValue the new property value

Since: 1.5

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the accessibility framework context of this class. Component is not accessible, so the default implementation returns null. Subclasses must override this behavior, and return an appropriate subclass of {@link AccessibleAWTComponent}.

Returns: the accessibility context

getAlignmentX

public float getAlignmentX()
Returns the preferred horizontal alignment of this component. The value returned will be between {@link #LEFT_ALIGNMENT} and {@link #RIGHT_ALIGNMENT}, inclusive.

Returns: the preferred horizontal alignment of this component

getAlignmentY

public float getAlignmentY()
Returns the preferred vertical alignment of this component. The value returned will be between {@link #TOP_ALIGNMENT} and {@link #BOTTOM_ALIGNMENT}, inclusive.

Returns: the preferred vertical alignment of this component

getBackground

public Color getBackground()
Returns this component's background color. If not set, this is inherited from the parent.

Returns: the background color of the component, or null

See Also: setBackground

getBounds

public Rectangle getBounds()
Returns a bounding rectangle for this component. Note that the returned rectange is relative to this component's parent, not to the screen.

Returns: the bounding rectangle for this component

See Also: Component getLocation getSize

getBounds

public Rectangle getBounds(Rectangle r)
Returns the bounds of this component. This allows reuse of an existing rectangle, if r is non-null.

Parameters: r the rectangle to use, or null

Returns: the bounds

getColorModel

public ColorModel getColorModel()
Returns the color model of the device this componet is displayed on.

Returns: this object's color model

See Also: getColorModel

getComponentAt

public Component getComponentAt(int x, int y)
Returns the component occupying the position (x,y). This will either be this component, an immediate child component, or null if neither of the first two occupies the specified location.

Parameters: x the X coordinate to search for components at y the Y coordinate to search for components at

Returns: the component at the specified location, or null

See Also: Component

getComponentAt

public Component getComponentAt(Point p)
Returns the component occupying the position (x,y). This will either be this component, an immediate child component, or null if neither of the first two occupies the specified location.

Parameters: p the point to search for components at

Returns: the component at the specified location, or null

Throws: NullPointerException if p is null

Since: 1.1

See Also: contains

getComponentListeners

public ComponentListener[] getComponentListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addComponentListener removeComponentListener

getComponentOrientation

public ComponentOrientation getComponentOrientation()
Determines the text layout orientation used by this component.

Returns: the component orientation (this can be null)

See Also: setComponentOrientation

getCursor

public Cursor getCursor()
Returns the cursor for this component. If not set, this is inherited from the parent, or from Cursor.getDefaultCursor().

Returns: the cursor for this component

getDropTarget

public DropTarget getDropTarget()
Gets the associated drag-and-drop target, if there is one.

Returns: the drop target

getFocusCycleRootAncestor

public Container getFocusCycleRootAncestor()
Returns the root container that owns the focus cycle where this component resides. A focus cycle root is in two cycles, one as the ancestor, and one as the focusable element; this call always returns the ancestor.

Returns: the ancestor container that owns the focus cycle

Since: 1.4

getFocusListeners

public FocusListener[] getFocusListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addFocusListener removeFocusListener

getFocusTraversalKeys

public Set<AWTKeyStroke> getFocusTraversalKeys(int id)
Returns the set of keys for a given focus traversal action, as defined in setFocusTraversalKeys. If not set, this is inherited from the parent component, which may have gotten it from the KeyboardFocusManager.

Parameters: id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or UP_CYCLE_TRAVERSAL_KEYS

Returns: set of traversal keys

Throws: IllegalArgumentException if id is invalid

Since: 1.4

See Also: Component FORWARD_TRAVERSAL_KEYS BACKWARD_TRAVERSAL_KEYS UP_CYCLE_TRAVERSAL_KEYS

getFocusTraversalKeysEnabled

public boolean getFocusTraversalKeysEnabled()
Check whether or not focus traversal keys are enabled on this Component. If they are, then the keyboard focus manager consumes and acts on key press and release events that trigger focus traversal, and discards the corresponding key typed events. If focus traversal keys are disabled, then all key events that would otherwise trigger focus traversal are sent to this Component.

Returns: true if focus traversal keys are enabled

Since: 1.4

See Also: Component Component Component

getFont

public Font getFont()
Returns the font in use for this component. If not set, this is inherited from the parent.

Returns: the font for this component

See Also: setFont

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Returns the font metrics for the specified font in this component.

Parameters: font the font to retrieve metrics for

Returns: the font metrics for the specified font

Throws: NullPointerException if font is null

See Also: getFont getFontMetrics

getForeground

public Color getForeground()
Returns this component's foreground color. If not set, this is inherited from the parent.

Returns: this component's foreground color, or null

See Also: setForeground

getGraphics

public Graphics getGraphics()
Returns a graphics object for this component. Returns null if this component is not currently displayed on the screen.

Returns: a graphics object for this component

See Also: paint

getGraphicsConfiguration

public GraphicsConfiguration getGraphicsConfiguration()
Returns the graphics configuration of this component, if there is one. If it has not been set, it is inherited from the parent.

Returns: the graphics configuration, or null

Since: 1.3

getHeight

public int getHeight()
Gets the height of the component. This is more efficient than getBounds().height or getSize().height.

Returns: the current width

Since: 1.2

getHierarchyBoundsListeners

public HierarchyBoundsListener[] getHierarchyBoundsListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addHierarchyBoundsListener removeHierarchyBoundsListener

getHierarchyListeners

public HierarchyListener[] getHierarchyListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addHierarchyListener removeHierarchyListener

getIgnoreRepaint

public boolean getIgnoreRepaint()
Test whether paint events from the operating system are ignored.

Returns: the status of ignoring paint events

Since: 1.4

See Also: Component

getInputContext

public InputContext getInputContext()
Gets the input context of this component, which is inherited from the parent unless this is overridden.

Returns: the text input context

Since: 1.2

getInputMethodListeners

public InputMethodListener[] getInputMethodListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addInputMethodListener removeInputMethodListener

getInputMethodRequests

public InputMethodRequests getInputMethodRequests()
Returns the input method request handler, for subclasses which support on-the-spot text input. By default, input methods are handled by AWT, and this returns null.

Returns: the input method handler, null by default

Since: 1.2

getKeyListeners

public KeyListener[] getKeyListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addKeyListener removeKeyListener

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns all registered {@link EventListener}s of the given listenerType.

Parameters: listenerType the class of listeners to filter (null not permitted).

Returns: An array of registered listeners.

Throws: ClassCastException if listenerType does not implement the {@link EventListener} interface. NullPointerException if listenerType is null.

Since: 1.3

See Also: getComponentListeners getFocusListeners getHierarchyListeners getHierarchyBoundsListeners getKeyListeners getMouseListeners getMouseMotionListeners getMouseWheelListeners getInputMethodListeners getPropertyChangeListeners

getLocale

public Locale getLocale()
Returns the locale for this component. If this component does not have a locale, the locale of the parent component is returned.

Returns: the locale for this component

Throws: IllegalComponentStateException if it has no locale or parent

Since: 1.1

See Also: setLocale

getLocation

public Point getLocation()
Returns the location of this component's top left corner relative to its parent component. This may be outdated, so for synchronous behavior, you should use a component listner.

Returns: the location of this component

Since: 1.1

See Also: Component getLocationOnScreen

getLocation

public Point getLocation(Point p)
Returns the location of this component. This allows reuse of an existing point, if p is non-null.

Parameters: p the point to use, or null

Returns: the location

getLocationOnScreen

public Point getLocationOnScreen()
Returns the location of this component's top left corner in screen coordinates.

Returns: the location of this component in screen coordinates

Throws: IllegalComponentStateException if the component is not showing

getMaximumSize

public Dimension getMaximumSize()
Returns the component's maximum size.

Returns: the component's maximum size

See Also: getMinimumSize setMaximumSize getPreferredSize LayoutManager

getMinimumSize

public Dimension getMinimumSize()
Returns the component's minimum size.

Returns: the component's minimum size

See Also: getPreferredSize setMinimumSize LayoutManager

getMouseListeners

public MouseListener[] getMouseListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addMouseListener removeMouseListener

getMouseMotionListeners

public MouseMotionListener[] getMouseMotionListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addMouseMotionListener removeMouseMotionListener

getMouseWheelListeners

public MouseWheelListener[] getMouseWheelListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addMouseWheelListener removeMouseWheelListener

getName

public String getName()
Returns the name of this component.

Returns: the name of this component

Since: 1.1

See Also: setName

getParent

public Container getParent()
Returns the parent of this component.

Returns: the parent of this component

getPeer

public ComponentPeer getPeer()

Deprecated: user programs should not directly manipulate peers; use {@link #isDisplayable()} instead

Returns the native windowing system peer for this component. Only the platform specific implementation code should call this method.

Returns: the peer for this component

getPreferredSize

public Dimension getPreferredSize()
Returns the component's preferred size.

Returns: the component's preferred size

See Also: getMinimumSize setPreferredSize LayoutManager

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all specified listeners registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: addPropertyChangeListener removePropertyChangeListener getPropertyChangeListeners

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners(String property)
Returns an array of all specified listeners on the named property that are registered on this component.

Returns: an array of listeners

Since: 1.4

See Also: Component Component getPropertyChangeListeners

getSize

public Dimension getSize()
Returns the size of this object.

Returns: the size of this object

Since: 1.1

See Also: Component

getSize

public Dimension getSize(Dimension d)
Returns the size of this component. This allows reuse of an existing dimension, if d is non-null.

Parameters: d the dimension to use, or null

Returns: the size

getToolkit

public Toolkit getToolkit()
Returns the toolkit in use for this component. The toolkit is associated with the frame this component belongs to.

Returns: the toolkit for this component

getTreeLock

public final Object getTreeLock()
Returns the object used for synchronization locks on this component when performing tree and layout functions.

Returns: the synchronization lock for this component

getWidth

public int getWidth()
Gets the width of the component. This is more efficient than getBounds().width or getSize().width.

Returns: the current width

Since: 1.2

getX

public int getX()
Gets the x coordinate of the upper left corner. This is more efficient than getBounds().x or getLocation().x.

Returns: the current x coordinate

Since: 1.2

getY

public int getY()
Gets the y coordinate of the upper left corner. This is more efficient than getBounds().y or getLocation().y.

Returns: the current y coordinate

Since: 1.2

gotFocus

public boolean gotFocus(Event evt, Object what)

Deprecated: use {@link #processFocusEvent(FocusEvent)} instead

AWT 1.0 GOT_FOCUS event handler. This method is meant to be overridden by components providing their own GOT_FOCUS handler. The default implementation simply returns false.

Parameters: evt the event to handle what the Object focused, ignored

Returns: false

handleEvent

public boolean handleEvent(Event evt)

Deprecated: use {@link #processEvent(AWTEvent)} instead

AWT 1.0 event handler. This method calls one of the event-specific handler methods. For example for key events, either {@link #keyDown(Event,int)} or {@link #keyUp(Event,int)} is called. A derived component can override one of these event-specific methods if it only needs to handle certain event types. Otherwise it can override handleEvent itself and handle any event.

Parameters: evt the event to handle

Returns: true if the event was handled, false otherwise

hasFocus

public boolean hasFocus()
Tests if this component is the focus owner. Use {@link #isFocusOwner ()} instead.

Returns: true if this component owns focus

Since: 1.2

hide

public void hide()

Deprecated: use {@link #setVisible(boolean)} instead

Hides this component so that it is no longer shown on the screen.

imageUpdate

public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
Called when an image has changed so that this component is repainted. This incrementally draws an image as more bits are available, when possible. Incremental drawing is enabled if the system property awt.image.incrementalDraw is not present or is true, in which case the redraw rate is set to 100ms or the value of the system property awt.image.redrawrate.

The coordinate system used depends on the particular flags.

Parameters: img the image that has been updated flags tlags as specified in ImageObserver x the X coordinate y the Y coordinate w the width h the height

Returns: false if the image is completely loaded, loading has been aborted, or an error has occurred. true if more updates are required.

See Also: ImageObserver Graphics Graphics Graphics Graphics ImageObserver

inside

public boolean inside(int x, int y)

Deprecated: use {@link #contains(int, int)} instead

Tests whether or not the specified point is contained within this component. Coordinates are relative to this component.

Parameters: x the X coordinate of the point to test y the Y coordinate of the point to test

Returns: true if the point is within this component

invalidate

public void invalidate()
Invalidates this component and all of its parent components. This will cause them to have their layout redone. This is called frequently, so make it fast.

isBackgroundSet

public boolean isBackgroundSet()
Tests if the background was explicitly set, or just inherited from the parent.

Returns: true if the background has been set

Since: 1.4

isCursorSet

public boolean isCursorSet()
Tests if the cursor was explicitly set, or just inherited from the parent.

Returns: true if the cursor has been set

Since: 1.4

isDisplayable

public boolean isDisplayable()
Tests if the component is displayable. It must be connected to a native screen resource. This reduces to checking that peer is not null. A containment hierarchy is made displayable when a window is packed or made visible.

Returns: true if the component is displayable

Since: 1.2

See Also: add remove pack show dispose

isDoubleBuffered

public boolean isDoubleBuffered()
Checks if this image is painted to an offscreen image buffer that is later copied to screen (double buffering reduces flicker). This version returns false, so subclasses must override it if they provide double buffering.

Returns: true if this is double buffered; defaults to false

isEnabled

public boolean isEnabled()
Tests whether or not this component is enabled. Components are enabled by default, and must be enabled to receive user input or generate events.

Returns: true if the component is enabled

See Also: Component

isFocusable

public boolean isFocusable()
Tests if this component can receive focus.

Returns: true if this component can receive focus

Since: 1.4

isFocusCycleRoot

public boolean isFocusCycleRoot(Container c)
Tests if the container is the ancestor of the focus cycle that this component belongs to.

Parameters: c the container to test

Returns: true if c is the focus cycle root

Since: 1.4

isFocusOwner

public boolean isFocusOwner()
Tests if this component is the focus owner.

Returns: true if this component owns focus

Since: 1.4

isFocusTraversable

public boolean isFocusTraversable()

Deprecated: use {@link #isFocusable()} instead

Tests whether or not this component is in the group that can be traversed using the keyboard traversal mechanism (such as the TAB key).

Returns: true if the component is traversed via the TAB key

Since: 1.1

See Also: Component

isFontSet

public boolean isFontSet()
Tests if the font was explicitly set, or just inherited from the parent.

Returns: true if the font has been set

Since: 1.4

isForegroundSet

public boolean isForegroundSet()
Tests if the foreground was explicitly set, or just inherited from the parent.

Returns: true if the foreground has been set

Since: 1.4

isLightweight

public boolean isLightweight()
Return whether the component is lightweight. That means the component has no native peer, but is displayable. This applies to subclasses of Component not in this package, such as javax.swing.

Returns: true if the component has a lightweight peer

Since: 1.2

See Also: isDisplayable

isMaximumSizeSet

public boolean isMaximumSizeSet()
Returns true if the current maximum size is not null and was set by a call to {@link #setMaximumSize(Dimension)}, otherwise returns false.

Returns: A boolean.

Since: 1.5

isMinimumSizeSet

public boolean isMinimumSizeSet()
Returns true if the current minimum size is not null and was set by a call to {@link #setMinimumSize(Dimension)}, otherwise returns false.

Returns: A boolean.

Since: 1.5

isOpaque

public boolean isOpaque()
Tests if this component is opaque. All "heavyweight" (natively-drawn) components are opaque. A component is opaque if it draws all pixels in the bounds; a lightweight component is partially transparent if it lets pixels underneath show through. Subclasses that guarantee that all pixels will be drawn should override this.

Returns: true if this is opaque

Since: 1.2

See Also: isLightweight

isPreferredSizeSet

public boolean isPreferredSizeSet()
Returns true if the current preferred size is not null and was set by a call to {@link #setPreferredSize(Dimension)}, otherwise returns false.

Returns: A boolean.

Since: 1.5

isShowing

public boolean isShowing()
Tests whether or not this component is actually being shown on the screen. This will be true if and only if it this component is visible and its parent components are all visible.

Returns: true if the component is showing on the screen

See Also: Component

isValid

public boolean isValid()
Tests whether or not this component is valid. A invalid component needs to have its layout redone.

Returns: true if this component is valid

See Also: validate invalidate

isVisible

public boolean isVisible()
Tests whether or not this component is visible. Except for top-level frames, components are initially visible.

Returns: true if the component is visible

See Also: Component

keyDown

public boolean keyDown(Event evt, int key)

Deprecated: use {@link #processKeyEvent(KeyEvent)} instead

AWT 1.0 KEY_PRESS and KEY_ACTION event handler. This method is meant to be overridden by components providing their own key press handler. The default implementation simply returns false.

Parameters: evt the event to handle key the key pressed, ignored

Returns: false

keyUp

public boolean keyUp(Event evt, int key)

Deprecated: use {@link #processKeyEvent(KeyEvent)} instead

AWT 1.0 KEY_RELEASE and KEY_ACTION_RELEASE event handler. This method is meant to be overridden by components providing their own key release handler. The default implementation simply returns false.

Parameters: evt the event to handle key the key pressed, ignored

Returns: false

layout

public void layout()

Deprecated: use {@link #doLayout()} instead

Calls the layout manager to re-layout the component. This is called during validation of a container in most cases.

list

public void list()
Prints a listing of this component to System.out.

See Also: list

list

public void list(PrintStream out)
Prints a listing of this component to the specified print stream.

Parameters: out the PrintStream to print to

list

public void list(PrintStream out, int indent)
Prints a listing of this component to the specified print stream, starting at the specified indentation point.

Parameters: out the PrintStream to print to indent the indentation point

list

public void list(PrintWriter out)
Prints a listing of this component to the specified print writer.

Parameters: out the PrintWrinter to print to

Since: 1.1

list

public void list(PrintWriter out, int indent)
Prints a listing of this component to the specified print writer, starting at the specified indentation point.

Parameters: out the PrintWriter to print to indent the indentation point

Since: 1.1

locate

public Component locate(int x, int y)

Deprecated: use {@link #getComponentAt(int, int)} instead

Returns the component occupying the position (x,y). This will either be this component, an immediate child component, or null if neither of the first two occupies the specified location.

Parameters: x the X coordinate to search for components at y the Y coordinate to search for components at

Returns: the component at the specified location, or null

location

public Point location()

Deprecated: use {@link #getLocation()} instead

Returns the location of this component's top left corner relative to its parent component.

Returns: the location of this component

lostFocus

public boolean lostFocus(Event evt, Object what)

Deprecated: use {@link #processFocusEvent(FocusEvent)} instead

AWT 1.0 LOST_FOCUS event handler. This method is meant to be overridden by components providing their own LOST_FOCUS handler. The default implementation simply returns false.

Parameters: evt the event to handle what the Object focused, ignored

Returns: false

minimumSize

public Dimension minimumSize()

Deprecated: use {@link #getMinimumSize()} instead

Returns the component's minimum size.

Returns: the component's minimum size

mouseDown

public boolean mouseDown(Event evt, int x, int y)

Deprecated: use {@link #processMouseEvent(MouseEvent)} instead

AWT 1.0 MOUSE_DOWN event handler. This method is meant to be overridden by components providing their own MOUSE_DOWN handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

mouseDrag

public boolean mouseDrag(Event evt, int x, int y)

Deprecated: use {@link #processMouseMotionEvent(MouseEvent)} instead

AWT 1.0 MOUSE_DRAG event handler. This method is meant to be overridden by components providing their own MOUSE_DRAG handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

mouseEnter

public boolean mouseEnter(Event evt, int x, int y)

Deprecated: use {@link #processMouseEvent(MouseEvent)} instead

AWT 1.0 MOUSE_ENTER event handler. This method is meant to be overridden by components providing their own MOUSE_ENTER handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

mouseExit

public boolean mouseExit(Event evt, int x, int y)

Deprecated: use {@link #processMouseEvent(MouseEvent)} instead

AWT 1.0 MOUSE_EXIT event handler. This method is meant to be overridden by components providing their own MOUSE_EXIT handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

mouseMove

public boolean mouseMove(Event evt, int x, int y)

Deprecated: use {@link #processMouseMotionEvent(MouseEvent)} instead

AWT 1.0 MOUSE_MOVE event handler. This method is meant to be overridden by components providing their own MOUSE_MOVE handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

mouseUp

public boolean mouseUp(Event evt, int x, int y)

Deprecated: use {@link #processMouseEvent(MouseEvent)} instead

AWT 1.0 MOUSE_UP event handler. This method is meant to be overridden by components providing their own MOUSE_UP handler. The default implementation simply returns false.

Parameters: evt the event to handle x the x coordinate, ignored y the y coordinate, ignored

Returns: false

move

public void move(int x, int y)

Deprecated: use {@link #setLocation(int, int)} instead

Moves this component to the specified location, relative to the parent's coordinates. The coordinates are the new upper left corner of this component.

Parameters: x the new X coordinate of this component y the new Y coordinate of this component

nextFocus

public void nextFocus()

Deprecated: use {@link #transferFocus ()} instead

AWT 1.0 focus event processor. Transfers focus to the next component in the focus traversal order, as though this were the current focus owner.

paint

public void paint(Graphics g)
Paints this component on the screen. The clipping region in the graphics context will indicate the region that requires painting. This is called whenever the component first shows, or needs to be repaired because something was temporarily drawn on top. It is not necessary for subclasses to call super.paint(g). Components with no area are not painted.

Parameters: g the graphics context for this paint job

See Also: update

paintAll

public void paintAll(Graphics g)
Paints this entire component, including any sub-components.

Parameters: g the graphics context for this paint job

See Also: paint

paramString

protected String paramString()
Returns a debugging string representing this component. The string may be empty but not null.

Returns: a string representing this component

postEvent

public boolean postEvent(Event e)

Deprecated: use {@link #dispatchEvent(AWTEvent)} instead

AWT 1.0 event handler. This method simply calls handleEvent and returns the result.

Parameters: e the event to handle

Returns: true if the event was handled, false otherwise

preferredSize

public Dimension preferredSize()

Deprecated: use {@link #getPreferredSize()} instead

Returns the component's preferred size.

Returns: the component's preferred size

prepareImage

public boolean prepareImage(Image image, ImageObserver observer)
Prepares the specified image for rendering on this component.

Parameters: image the image to prepare for rendering observer the observer to notify of image preparation status

Returns: true if the image is already fully prepared

Throws: NullPointerException if image is null

prepareImage

public boolean prepareImage(Image image, int width, int height, ImageObserver observer)
Prepares the specified image for rendering on this component at the specified scaled width and height

Parameters: image the image to prepare for rendering width the scaled width of the image height the scaled height of the image observer the observer to notify of image preparation status

Returns: true if the image is already fully prepared

print

public void print(Graphics g)
Prints this component. This method is provided so that printing can be done in a different manner from painting. However, the implementation in this class simply calls the paint() method.

Parameters: g the graphics context of the print device

See Also: paint

printAll

public void printAll(Graphics g)
Prints this component, including all sub-components.

Parameters: g the graphics context of the print device

See Also: paintAll

processComponentEvent

protected void processComponentEvent(ComponentEvent e)
Called when a component event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the ComponentEvent to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: ComponentListener addComponentListener Component

processEvent

protected void processEvent(AWTEvent e)
Processes the specified event. In this class, this method simply calls one of the more specific event handlers.

Parameters: e the event to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: processComponentEvent processFocusEvent processKeyEvent processMouseEvent processMouseMotionEvent processInputMethodEvent processHierarchyEvent processMouseWheelEvent

processFocusEvent

protected void processFocusEvent(FocusEvent e)
Called when a focus event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the FocusEvent to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: FocusListener addFocusListener Component

processHierarchyBoundsEvent

protected void processHierarchyBoundsEvent(HierarchyEvent e)
Called when a hierarchy bounds event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the HierarchyEvent to process

Throws: NullPointerException if e is null

Since: 1.3

See Also: HierarchyBoundsListener addHierarchyBoundsListener Component

processHierarchyEvent

protected void processHierarchyEvent(HierarchyEvent e)
Called when a hierarchy change event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the HierarchyEvent to process

Throws: NullPointerException if e is null

Since: 1.3

See Also: HierarchyListener addHierarchyListener Component

processInputMethodEvent

protected void processInputMethodEvent(InputMethodEvent e)
Called when an input method event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the InputMethodEvent to process

Throws: NullPointerException if e is null

Since: 1.2

See Also: InputMethodListener addInputMethodListener Component

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Called when a key event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the KeyEvent to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: KeyListener addKeyListener Component

processMouseEvent

protected void processMouseEvent(MouseEvent e)
Called when a regular mouse event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the MouseEvent to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: MouseListener addMouseListener Component

processMouseMotionEvent

protected void processMouseMotionEvent(MouseEvent e)
Called when a mouse motion event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the MouseMotionEvent to process

Throws: NullPointerException if e is null

Since: 1.1

See Also: MouseMotionListener addMouseMotionListener Component

processMouseWheelEvent

protected void processMouseWheelEvent(MouseWheelEvent e)
Called when a mouse wheel event is dispatched and component events are enabled. This method passes the event along to any listeners that are attached.

Parameters: e the MouseWheelEvent to process

Throws: NullPointerException if e is null

Since: 1.4

See Also: MouseWheelListener addMouseWheelListener Component

remove

public void remove(MenuComponent popup)
Removes the specified popup menu from this component.

Parameters: popup the popup menu to remove

Since: 1.1

See Also: add

removeComponentListener

public void removeComponentListener(ComponentListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: ComponentEvent addComponentListener getComponentListeners

removeFocusListener

public void removeFocusListener(FocusListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: FocusEvent addFocusListener getFocusListeners

removeHierarchyBoundsListener

public void removeHierarchyBoundsListener(HierarchyBoundsListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.3

See Also: HierarchyEvent addHierarchyBoundsListener getHierarchyBoundsListeners

removeHierarchyListener

public void removeHierarchyListener(HierarchyListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.3

See Also: HierarchyEvent addHierarchyListener getHierarchyListeners

removeInputMethodListener

public void removeInputMethodListener(InputMethodListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.2

See Also: InputMethodEvent addInputMethodListener getInputMethodRequests

removeKeyListener

public void removeKeyListener(KeyListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: KeyEvent addKeyListener getKeyListeners

removeMouseListener

public void removeMouseListener(MouseListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: MouseEvent addMouseListener getMouseListeners

removeMouseMotionListener

public void removeMouseMotionListener(MouseMotionListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: MouseEvent addMouseMotionListener getMouseMotionListeners

removeMouseWheelListener

public void removeMouseWheelListener(MouseWheelListener listener)
Removes the specified listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.4

See Also: MouseEvent MouseWheelEvent addMouseWheelListener getMouseWheelListeners

removeNotify

public void removeNotify()
Called to inform this component is has been removed from its container. Its native peer - if any - is destroyed at this time. This method is called automatically by the AWT system and should not be called by user level code.

See Also: isDisplayable addNotify

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified property listener from the component. This is harmless if the listener was not previously registered.

Parameters: listener the listener to remove

Since: 1.1

See Also: addPropertyChangeListener getPropertyChangeListeners Component

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
Removes the specified property listener on a particular property from the component. This is harmless if the listener was not previously registered.

Parameters: propertyName the property name to filter on listener the listener to remove

Since: 1.1

See Also: Component getPropertyChangeListeners removePropertyChangeListener

repaint

public void repaint()
Repaint this entire component. The update() method on this component will be called as soon as possible.

See Also: update Component

repaint

public void repaint(long tm)
Repaint this entire component. The update() method on this component will be called in approximate the specified number of milliseconds.

Parameters: tm milliseconds before this component should be repainted

See Also: paint Component

repaint

public void repaint(int x, int y, int w, int h)
Repaints the specified rectangular region within this component. The update method on this component will be called as soon as possible. The coordinates are relative to this component.

Parameters: x the X coordinate of the upper left of the region to repaint y the Y coordinate of the upper left of the region to repaint w the width of the region to repaint h the height of the region to repaint

See Also: update Component

repaint

public void repaint(long tm, int x, int y, int width, int height)
Repaints the specified rectangular region within this component. The update method on this component will be called in approximately the specified number of milliseconds. The coordinates are relative to this component.

Parameters: tm milliseconds before this component should be repainted x the X coordinate of the upper left of the region to repaint y the Y coordinate of the upper left of the region to repaint width the width of the region to repaint height the height of the region to repaint

See Also: update

requestFocus

public void requestFocus()
Request that this Component be given the keyboard input focus and that its top-level ancestor become the focused Window. For the request to be granted, the Component must be focusable, displayable and showing and the top-level Window to which it belongs must be focusable. If the request is initially denied on the basis that the top-level Window is not focusable, the request will be remembered and granted when the Window does become focused. Never assume that this Component is the focus owner until it receives a FOCUS_GAINED event. The behaviour of this method is platform-dependent. {@link #requestFocusInWindow()} should be used instead.

See Also: requestFocusInWindow FocusEvent addFocusListener isFocusable isDisplayable clearGlobalFocusOwner

requestFocus

protected boolean requestFocus(boolean temporary)
Request that this Component be given the keyboard input focus and that its top-level ancestor become the focused Window. For the request to be granted, the Component must be focusable, displayable and showing and the top-level Window to which it belongs must be focusable. If the request is initially denied on the basis that the top-level Window is not focusable, the request will be remembered and granted when the Window does become focused. Never assume that this Component is the focus owner until it receives a FOCUS_GAINED event. The behaviour of this method is platform-dependent. {@link #requestFocusInWindow()} should be used instead. If the return value is false, the request is guaranteed to fail. If the return value is true, the request will succeed unless it is vetoed or something in the native windowing system intervenes, preventing this Component's top-level ancestor from becoming focused. This method is meant to be called by derived lightweight Components that want to avoid unnecessary repainting when they know a given focus transfer need only be temporary.

Parameters: temporary true if the focus request is temporary

Returns: true if the request has a chance of success

Since: 1.4

See Also: requestFocusInWindow FocusEvent addFocusListener isFocusable isDisplayable clearGlobalFocusOwner

requestFocusInWindow

public boolean requestFocusInWindow()
Request that this component be given the keyboard input focus, if its top-level ancestor is the currently focused Window. A FOCUS_GAINED event will be fired if and only if this request is successful. To be successful, the component must be displayable, showing, and focusable, and its ancestor top-level Window must be focused. If the return value is false, the request is guaranteed to fail. If the return value is true, the request will succeed unless it is vetoed or something in the native windowing system intervenes, preventing this Component's top-level ancestor from becoming focused.

Returns: true if the request has a chance of success

Since: 1.4

See Also: requestFocus FocusEvent addFocusListener isFocusable isDisplayable clearGlobalFocusOwner

requestFocusInWindow

protected boolean requestFocusInWindow(boolean temporary)
Request that this component be given the keyboard input focus, if its top-level ancestor is the currently focused Window. A FOCUS_GAINED event will be fired if and only if this request is successful. To be successful, the component must be displayable, showing, and focusable, and its ancestor top-level Window must be focused. If the return value is false, the request is guaranteed to fail. If the return value is true, the request will succeed unless it is vetoed or something in the native windowing system intervenes, preventing this Component's top-level ancestor from becoming focused. This method is meant to be called by derived lightweight Components that want to avoid unnecessary repainting when they know a given focus transfer need only be temporary.

Parameters: temporary true if the focus request is temporary

Returns: true if the request has a chance of success

Since: 1.4

See Also: requestFocus FocusEvent addFocusListener isFocusable isDisplayable clearGlobalFocusOwner

reshape

public void reshape(int x, int y, int width, int height)

Deprecated: use {@link #setBounds(int, int, int, int)} instead

Sets the bounding rectangle for this component to the specified values. Note that these coordinates are relative to the parent, not to the screen.

Parameters: x the X coordinate of the upper left corner of the rectangle y the Y coordinate of the upper left corner of the rectangle width the width of the rectangle height the height of the rectangle

resize

public void resize(int width, int height)

Deprecated: use {@link #setSize(int, int)} instead

Sets the size of this component to the specified value.

Parameters: width the new width of the component height the new height of the component

resize

public void resize(Dimension d)

Deprecated: use {@link #setSize(Dimension)} instead

Sets the size of this component to the specified value.

Parameters: d the new size of this component

Throws: NullPointerException if d is null

setBackground

public void setBackground(Color c)
Sets this component's background color to the specified color. The parts of the component affected by the background color may by system dependent. This is a bound property.

Parameters: c the new background color

See Also: getBackground

setBounds

public void setBounds(int x, int y, int w, int h)
Sets the bounding rectangle for this component to the specified values. Note that these coordinates are relative to the parent, not to the screen.

Parameters: x the X coordinate of the upper left corner of the rectangle y the Y coordinate of the upper left corner of the rectangle w the width of the rectangle h the height of the rectangle

Since: 1.1

See Also: getBounds Component setLocation Component setSize

setBounds

public void setBounds(Rectangle r)
Sets the bounding rectangle for this component to the specified rectangle. Note that these coordinates are relative to the parent, not to the screen.

Parameters: r the new bounding rectangle

Throws: NullPointerException if r is null

Since: 1.1

See Also: getBounds setLocation setSize

setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Sets the text layout orientation of this component. New components default to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only the current component, while {@link #applyComponentOrientation(ComponentOrientation)} affects the entire hierarchy.

Parameters: o the new orientation (null is accepted)

See Also: getComponentOrientation

setCursor

public void setCursor(Cursor cursor)
Sets the cursor for this component to the specified cursor. The cursor is displayed when the point is contained by the component, and the component is visible, displayable, and enabled. This is inherited by subcomponents unless they set their own cursor.

Parameters: cursor the new cursor for this component

See Also: isEnabled isShowing getCursor Component Toolkit

setDropTarget

public void setDropTarget(DropTarget dt)
Set the associated drag-and-drop target, which receives events when this is enabled.

Parameters: dt the new drop target

See Also: isEnabled

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this component. The component must be enabled to receive events (except that lightweight components always receive mouse events).

Parameters: enabled true to enable this component

Since: 1.1

See Also: isEnabled

setFocusable

public void setFocusable(boolean focusable)
Specify whether this component can receive focus. This method also sets the {@link #isFocusTraversableOverridden} field to 1, which appears to be the undocumented way {@link DefaultFocusTraversalPolicy#accept(Component)} determines whether to respect the {@link #isFocusable()} method of the component.

Parameters: focusable the new focusable status

Since: 1.4

setFocusTraversalKeys

public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
Sets the focus traversal keys for one of the three focus traversal directions supported by Components: {@link KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS}, {@link KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS}, or {@link KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS}. Normally, the default values should match the operating system's native choices. To disable a given traversal, use Collections.EMPTY_SET. The event dispatcher will consume PRESSED, RELEASED, and TYPED events for the specified key, although focus can only transfer on PRESSED or RELEASED.

The defaults are:

IdentifierMeaningDefault
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS Normal forward traversal TAB on KEY_PRESSED, Ctrl-TAB on KEY_PRESSED
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS Normal backward traversal Shift-TAB on KEY_PRESSED, Ctrl-Shift-TAB on KEY_PRESSED
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS Go up a traversal cycleNone
If keystrokes is null, this component's focus traversal key set is inherited from one of its ancestors. If none of its ancestors has its own set of focus traversal keys, the focus traversal keys are set to the defaults retrieved from the current KeyboardFocusManager. If not null, the set must contain only AWTKeyStrokes that are not already focus keys and are not KEY_TYPED events.

Parameters: id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or UP_CYCLE_TRAVERSAL_KEYS keystrokes a set of keys, or null

Throws: IllegalArgumentException if id or keystrokes is invalid

Since: 1.4

See Also: Component FORWARD_TRAVERSAL_KEYS BACKWARD_TRAVERSAL_KEYS UP_CYCLE_TRAVERSAL_KEYS

setFocusTraversalKeysEnabled

public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
Enable or disable focus traversal keys on this Component. If they are, then the keyboard focus manager consumes and acts on key press and release events that trigger focus traversal, and discards the corresponding key typed events. If focus traversal keys are disabled, then all key events that would otherwise trigger focus traversal are sent to this Component.

Parameters: focusTraversalKeysEnabled the new value of the flag

Since: 1.4

See Also: getFocusTraversalKeysEnabled Component Component

setFont

public void setFont(Font f)
Sets the font for this component to the specified font. This is a bound property.

Parameters: f the new font for this component

See Also: getFont

setForeground

public void setForeground(Color c)
Sets this component's foreground color to the specified color. This is a bound property.

Parameters: c the new foreground color

See Also: getForeground

setIgnoreRepaint

public void setIgnoreRepaint(boolean ignoreRepaint)
Sets whether paint messages delivered by the operating system should be ignored. This does not affect messages from AWT, except for those triggered by OS messages. Setting this to true can allow faster performance in full-screen mode or page-flipping.

Parameters: ignoreRepaint the new setting for ignoring repaint events

Since: 1.4

See Also: getIgnoreRepaint BufferStrategy setFullScreenWindow

setLocale

public void setLocale(Locale newLocale)
Sets the locale for this component to the specified locale. This is a bound property.

Parameters: newLocale the new locale for this component

setLocation

public void setLocation(int x, int y)
Moves this component to the specified location, relative to the parent's coordinates. The coordinates are the new upper left corner of this component.

Parameters: x the new X coordinate of this component y the new Y coordinate of this component

See Also: getLocation Component

setLocation

public void setLocation(Point p)
Moves this component to the specified location, relative to the parent's coordinates. The coordinates are the new upper left corner of this component.

Parameters: p new coordinates for this component

Throws: NullPointerException if p is null

Since: 1.1

See Also: getLocation Component

setMaximumSize

public void setMaximumSize(Dimension size)
Sets the maximum size that will be returned by {@link #getMaximumSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'maximumSize') to all registered listeners.

Parameters: size the maximum size (null permitted).

Since: 1.5

See Also: getMaximumSize

setMinimumSize

public void setMinimumSize(Dimension size)
Sets the minimum size that will be returned by {@link #getMinimumSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'minimumSize') to all registered listeners.

Parameters: size the minimum size (null permitted).

Since: 1.5

See Also: getMinimumSize

setName

public void setName(String name)
Sets the name of this component to the specified name (this is a bound property with the name 'name').

Parameters: name the new name (null permitted).

Since: 1.1

See Also: getName

setPreferredSize

public void setPreferredSize(Dimension size)
Sets the preferred size that will be returned by {@link #getPreferredSize()} always, and sends a {@link PropertyChangeEvent} (with the property name 'preferredSize') to all registered listeners.

Parameters: size the preferred size (null permitted).

Since: 1.5

See Also: getPreferredSize

setSize

public void setSize(int width, int height)
Sets the size of this component to the specified width and height.

Parameters: width the new width of this component height the new height of this component

See Also: getSize Component

setSize

public void setSize(Dimension d)
Sets the size of this component to the specified value.

Parameters: d the new size of this component

Throws: NullPointerException if d is null

Since: 1.1

See Also: Component Component

setVisible

public void setVisible(boolean visible)
Makes this component visible or invisible. Note that it wtill might not show the component, if a parent is invisible.

Parameters: visible true to make this component visible

Since: 1.1

See Also:

show

public void show()

Deprecated: use {@link #setVisible(boolean)} instead

Makes this component visible on the screen.

show

public void show(boolean visible)

Deprecated: use {@link #setVisible(boolean)} instead

Makes this component visible or invisible.

Parameters: visible true to make this component visible

size

public Dimension size()

Deprecated: use {@link #getSize()} instead

Returns the size of this object.

Returns: the size of this object

toString

public String toString()
Returns a string representation of this component. This is implemented as getClass().getName() + '[' + paramString() + ']'.

Returns: a string representation of this component

transferFocus

public void transferFocus()
Transfers focus to the next component in the focus traversal order, as though this were the current focus owner.

Since: 1.1

See Also: requestFocus

transferFocusBackward

public void transferFocusBackward()
Transfers focus to the previous component in the focus traversal order, as though this were the current focus owner.

Since: 1.4

See Also: requestFocus

transferFocusUpCycle

public void transferFocusUpCycle()
Transfers focus to the focus cycle root of this component. However, if this is a Window, the default focus owner in the window in the current focus cycle is focused instead.

Since: 1.4

See Also: requestFocus isFocusCycleRoot

update

public void update(Graphics g)
Updates this component. This is called for heavyweight components in response to {@link #repaint()}. The default implementation simply forwards to {@link #paint(Graphics)}. The coordinates of the graphics are relative to this component. Subclasses should call either super.update(g) or paint(g).

Parameters: g the graphics context for this update

See Also: paint repaint

validate

public void validate()
Called to ensure that the layout for this component is valid. This is usually called on containers.

See Also: invalidate doLayout LayoutManager validate