java.awt.event

Class FocusEvent

public class FocusEvent extends ComponentEvent

This class represents an event generated when a focus change occurs for a component. There are both temporary changes, such as when focus is stolen during a sroll then returned, and permanent changes, such as when the user TABs through focusable components.

Since: 1.1

See Also: FocusAdapter FocusListener

UNKNOWN: updated to 1.4

Field Summary
static intFOCUS_FIRST
This is the first id in the range of ids used by this class.
static intFOCUS_GAINED
This is the event id for a focus gained event.
static intFOCUS_LAST
This is the last id in the range of ids used by this class.
static intFOCUS_LOST
This is the event id for a focus lost event.
Constructor Summary
FocusEvent(Component source, int id, boolean temporary, Component opposite)
Initializes a new instance of FocusEvent with the specified source, id, temporary status, and opposite counterpart.
FocusEvent(Component source, int id, boolean temporary)
Initializes a new instance of FocusEvent with the specified source, id, and temporary status.
FocusEvent(Component source, int id)
Initializes a new instance of FocusEvent with the specified source and id.
Method Summary
ComponentgetOppositeComponent()
Returns the component which received the opposite focus event.
booleanisTemporary()
This method tests whether or not the focus change is temporary or permanent.
StringparamString()
Returns a string identifying this event.

Field Detail

FOCUS_FIRST

public static final int FOCUS_FIRST
This is the first id in the range of ids used by this class.

FOCUS_GAINED

public static final int FOCUS_GAINED
This is the event id for a focus gained event.

FOCUS_LAST

public static final int FOCUS_LAST
This is the last id in the range of ids used by this class.

FOCUS_LOST

public static final int FOCUS_LOST
This is the event id for a focus lost event.

Constructor Detail

FocusEvent

public FocusEvent(Component source, int id, boolean temporary, Component opposite)
Initializes a new instance of FocusEvent with the specified source, id, temporary status, and opposite counterpart. Note that an invalid id leads to unspecified results.

Parameters: source the component that is gaining or losing focus id the event id temporary true if the focus change is temporary opposite the component receiving the opposite focus event, or null

Throws: IllegalArgumentException if source is null

FocusEvent

public FocusEvent(Component source, int id, boolean temporary)
Initializes a new instance of FocusEvent with the specified source, id, and temporary status. Note that an invalid id leads to unspecified results.

Parameters: source the component that is gaining or losing focus id the event id temporary true if the focus change is temporary

Throws: IllegalArgumentException if source is null

FocusEvent

public FocusEvent(Component source, int id)
Initializes a new instance of FocusEvent with the specified source and id. Note that an invalid id leads to unspecified results.

Parameters: source the component that is gaining or losing focus id the event id

Throws: IllegalArgumentException if source is null

Method Detail

getOppositeComponent

public Component getOppositeComponent()
Returns the component which received the opposite focus event. If this component gained focus, the opposite lost focus; likewise if this component is giving up focus, the opposite is gaining it. If this information is unknown, perhaps because the opposite is a native application, this returns null.

Returns: the component with the focus opposite, or null

Since: 1.4

isTemporary

public boolean isTemporary()
This method tests whether or not the focus change is temporary or permanent.

Returns: true if the focus change is temporary

paramString

public String paramString()
Returns a string identifying this event. This is formatted as: (getID() == FOCUS_GAINED ? "FOCUS_GAINED" : "FOCUS_LOST") + (isTemporary() ? ",temporary," : ",permanent,") + "opposite=" + getOppositeComponent().

Returns: a string identifying this event