APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.event

public Class ComponentEvent

extends AWTEvent
Class Inheritance
Known Direct Subclasses
java.awt.event.ContainerEvent, java.awt.event.FocusEvent, java.awt.event.InputEvent, java.awt.event.PaintEvent, java.awt.event.WindowEvent
Imports
java.awt.AWTEvent, .Component, .Rectangle, java.io.Serial, java.lang.annotation.Native

A low-level event which indicates that a component moved, changed size, or changed visibility (also, the root class for the other component-level events).

Component events are provided for notification purposes ONLY; The AWT will automatically handle component moves and resizes internally so that GUI layout works properly regardless of whether a program is receiving these events or not.

In addition to serving as the base class for other component-related events (InputEvent, FocusEvent, WindowEvent, ContainerEvent), this class defines the events that indicate changes in a component's size, position, or visibility.

This low-level event is generated by a component object (such as a List) when the component is moved, resized, rendered invisible, or made visible again. The event is passed to every ComponentListener or ComponentAdapter object which registered to receive such events using the component's addComponentListener method. (ComponentAdapter objects implement the ComponentListener interface.) Each such listener object gets this ComponentEvent when the event occurs.

An unspecified behavior will be caused if the id parameter of any particular ComponentEvent instance is not in the range from COMPONENT_FIRST to COMPONENT_LAST.

Author
Carl Quinn
Since
1.1
See Also
ComponentAdapter, ComponentListener, Tutorial: Writing a Component Listener

Field Summary

Modifier and TypeField and Description
public static final int
COMPONENT_FIRST

The first number in the range of ids used for component events.

public static final int
COMPONENT_HIDDEN

This event indicates that the component was rendered invisible.

public static final int
COMPONENT_LAST

The last number in the range of ids used for component events.

public static final int
COMPONENT_MOVED

This event indicates that the component's position changed.

public static final int
COMPONENT_RESIZED

This event indicates that the component's size changed.

public static final int
COMPONENT_SHOWN

This event indicates that the component was made visible.

private static final long
serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
Inherited from java.awt.AWTEvent:
ACTION_EVENT_MASKADJUSTMENT_EVENT_MASKCOMPONENT_EVENT_MASKconsumedCONTAINER_EVENT_MASKFOCUS_EVENT_MASKHIERARCHY_BOUNDS_EVENT_MASKHIERARCHY_EVENT_MASKidINPUT_METHOD_EVENT_MASKINVOCATION_EVENT_MASKITEM_EVENT_MASKKEY_EVENT_MASKMOUSE_EVENT_MASKMOUSE_MOTION_EVENT_MASKMOUSE_WHEEL_EVENT_MASKPAINT_EVENT_MASKRESERVED_ID_MAXTEXT_EVENT_MASKWINDOW_EVENT_MASKWINDOW_FOCUS_EVENT_MASKWINDOW_STATE_EVENT_MASK

Constructor Summary

AccessConstructor and Description
public
ComponentEvent(Component
The Component that originated the event
source
,
int
An integer indicating the type of event. For information on allowable values, see the class description for ComponentEvent
id
)

Constructs a ComponentEvent object.

Method Summary

Modifier and TypeMethod and Description
public Component

Returns:

the Component object that originated the event, or null if the object is not a Component.
getComponent
()

Returns the originator of the event.

public String

Returns:

a string identifying the event and its attributes
paramString
()

Overrides java.awt.AWTEvent.paramString.

Returns a parameter string identifying this event.

Inherited from java.awt.AWTEvent:
consumegetIDisConsumedsetSourcetoString

Field Detail

COMPONENT_FIRSTback to summary
public static final int COMPONENT_FIRST

The first number in the range of ids used for component events.

COMPONENT_HIDDENback to summary
public static final int COMPONENT_HIDDEN

This event indicates that the component was rendered invisible.

Annotations
@Native
COMPONENT_LASTback to summary
public static final int COMPONENT_LAST

The last number in the range of ids used for component events.

COMPONENT_MOVEDback to summary
public static final int COMPONENT_MOVED

This event indicates that the component's position changed.

Annotations
@Native
COMPONENT_RESIZEDback to summary
public static final int COMPONENT_RESIZED

This event indicates that the component's size changed.

Annotations
@Native
COMPONENT_SHOWNback to summary
public static final int COMPONENT_SHOWN

This event indicates that the component was made visible.

Annotations
@Native
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.AWTEvent.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial

Constructor Detail

ComponentEventback to summary
public ComponentEvent(Component source, int id)

Constructs a ComponentEvent object.

This method throws an IllegalArgumentException if source is null.

Parameters
source:Component

The Component that originated the event

id:int

An integer indicating the type of event. For information on allowable values, see the class description for ComponentEvent

Exceptions
IllegalArgumentException:
if source is null
See Also
getComponent(), getID()

Method Detail

getComponentback to summary
public Component getComponent()

Returns the originator of the event.

Returns:Component

the Component object that originated the event, or null if the object is not a Component.

paramStringback to summary
public String paramString()

Overrides java.awt.AWTEvent.paramString.

Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.

Returns:String

a string identifying the event and its attributes