FocusListener or
FocusAdapter object which registered to receive such events
using the Component's addFocusListener method.
(FocusAdapter objects implement the FocusListener
interface.) Each such listener object gets this FocusEvent when
the event occurs.
There are two levels of focus events: permanent and temporary. Permanent focus change events occur when focus is directly moved from one Component to another, such as through a call to requestFocus() or as the user uses the TAB key to traverse Components. Temporary focus change events occur when focus is temporarily lost for a Component as the indirect result of another operation, such as Window deactivation or a Scrollbar drag. In this case, the original focus state will automatically be restored once that operation is finished, or, for the case of Window deactivation, when the Window is reactivated. Both permanent and temporary focus events are delivered using the FOCUS_GAINED and FOCUS_LOST event ids; the level may be distinguished in the event using the isTemporary() method.
Every FocusEvent records its cause - the reason why this event was
generated. The cause is assigned during the focus event creation and may be
retrieved by calling getCause.
An unspecified behavior will be caused if the id parameter
of any particular FocusEvent instance is not
in the range from FOCUS_FIRST to FOCUS_LAST.
FocusAdapter, FocusListener, Tutorial: Writing a Focus Listener
| Modifier and Type | Class and Description |
|---|---|
| public static enum | FocusEvent.
This enum represents the cause of a |
| Modifier and Type | Field and Description |
|---|---|
| private final FocusEvent. | cause
A focus event has the reason why this event was generated. |
| public static final int | FOCUS_FIRST
The first number in the range of ids used for focus events. |
| public static final int | FOCUS_GAINED
This event indicates that the Component is now the focus owner. |
| public static final int | FOCUS_LAST
The last number in the range of ids used for focus events. |
| public static final int | FOCUS_LOST
This event indicates that the Component is no longer the focus owner. |
| pack-priv transient Component | opposite
The other Component involved in this focus change. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
| pack-priv boolean | temporary
A focus event can have two different levels, permanent and temporary. |
| Access | Constructor and Description |
|---|---|
| public | FocusEvent(Component
The source, int Component that originated the eventAn integer indicating the type of event.
For information on allowable values, see
the class description for id, boolean FocusEventEquals temporary, Component true if the focus change is temporary;
false otherwiseThe other Component involved in the focus change,
or opposite)nullConstructs a |
| public | FocusEvent(Component
The source, int Component that originated the eventAn integer indicating the type of event.
For information on allowable values, see
the class description for id, boolean FocusEventEquals temporary, Component true if the focus change is temporary;
false otherwiseThe other Component involved in the focus change,
or opposite, FocusEvent.nullThe focus event cause. causeConstructs a |
| public | FocusEvent(Component
The source, int Component that originated the eventAn integer indicating the type of event.
For information on allowable values, see
the class description for id, boolean FocusEventEquals temporary)true if the focus change is temporary;
false otherwiseConstructs a |
| public | FocusEvent(Component
The source, int Component that originated the eventAn integer indicating the type of event.
For information on allowable values, see
the class description for id)FocusEventConstructs a |
| Modifier and Type | Method and Description |
|---|---|
| public final FocusEvent. | |
| public Component | Returns: the other Component involved in the focus change, or nullReturns the other Component involved in this focus change. |
| public boolean | Returns: true if the focus change is temporary;
false otherwiseIdentifies the focus change event as temporary or permanent. |
| public String | Returns: a string identifying the event and its attributesOverrides java. Returns a parameter string identifying this event. |
| pack-priv Object | Returns: a newly created object from deserialized dataChecks if this deserialized |
| cause | back to summary |
|---|---|
| private final FocusEvent. A focus event has the reason why this event was generated. The cause is set during the focus event creation.
| |
| FOCUS_FIRST | back to summary |
|---|---|
| public static final int FOCUS_FIRST The first number in the range of ids used for focus events. | |
| FOCUS_GAINED | back to summary |
|---|---|
| public static final int FOCUS_GAINED This event indicates that the Component is now the focus owner. | |
| FOCUS_LAST | back to summary |
|---|---|
| public static final int FOCUS_LAST The last number in the range of ids used for focus events. | |
| FOCUS_LOST | back to summary |
|---|---|
| public static final int FOCUS_LOST This event indicates that the Component is no longer the focus owner. | |
| opposite | back to summary |
|---|---|
| pack-priv transient Component opposite The other Component involved in this focus change. For a FOCUS_GAINED event, this is the Component that lost focus. For a FOCUS_LOST event, this is the Component that gained focus. If this focus change occurs with a native application, a Java application in a different VM, or with no other Component, then the opposite Component is null.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. | |
| temporary | back to summary |
|---|---|
| pack-priv boolean temporary A focus event can have two different levels, permanent and temporary. It will be set to true if some operation takes away the focus temporarily and intends on getting it back once the event is completed. Otherwise it will be set to false.
| |
| FocusEvent | back to summary |
|---|---|
| public FocusEvent(Component source, int id, boolean temporary, Component opposite) Constructs a This method throws an
| |
| FocusEvent | back to summary |
|---|---|
| public FocusEvent(Component source, int id, boolean temporary, Component opposite, FocusEvent. Constructs a This method throws an
| |
| FocusEvent | back to summary |
|---|---|
| public FocusEvent(Component source, int id, boolean temporary) Constructs a This method throws an
| |
| FocusEvent | back to summary |
|---|---|
| public FocusEvent(Component source, int id) Constructs a This method throws an
| |
| getCause | back to summary |
|---|---|
| public final FocusEvent. Returns the event cause.
| |
| getOppositeComponent | back to summary |
|---|---|
| public Component getOppositeComponent() Returns the other Component involved in this focus change. For a FOCUS_GAINED event, this is the Component that lost focus. For a FOCUS_LOST event, this is the Component that gained focus. If this focus change occurs with a native application, with a Java application in a different VM, or with no other Component, then null is returned.
| |
| isTemporary | back to summary |
|---|---|
| public boolean isTemporary() Identifies the focus change event as temporary or permanent.
| |
| paramString | back to summary |
|---|---|
| public String paramString() Overrides java. Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.
| |
| readResolve | back to summary |
|---|---|
| pack-priv Object readResolve() throws ObjectStreamException Checks if this deserialized
| |
FocusEvent- the reason why it
occurred. Possible reasons include mouse events, keyboard focus
traversal, window activation.
If no cause is provided then the reason is UNKNOWN.
| Modifier and Type | Field and Description |
|---|---|
| public static final FocusEvent. | ACTIVATION
An activation of a toplevel window. |
| public static final FocusEvent. | CLEAR_GLOBAL_FOCUS_OWNER
Clearing global focus owner. |
| public static final FocusEvent. | MOUSE_EVENT
An activating mouse event. |
| public static final FocusEvent. | ROLLBACK
Restoring focus after a focus request has been rejected. |
| public static final FocusEvent. | TRAVERSAL
A focus traversal action with unspecified direction. |
| public static final FocusEvent. | TRAVERSAL_BACKWARD
A backward focus traversal action. |
| public static final FocusEvent. | TRAVERSAL_DOWN
A down-cycle focus traversal action. |
| public static final FocusEvent. | TRAVERSAL_FORWARD
A forward focus traversal action. |
| public static final FocusEvent. | TRAVERSAL_UP
An up-cycle focus traversal action. |
| public static final FocusEvent. | UNEXPECTED
A system action causing an unexpected focus change. |
| public static final FocusEvent. | UNKNOWN
The default value. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static FocusEvent. | |
| public static FocusEvent. |
| ACTIVATION | back to summary |
|---|---|
| public static final FocusEvent. An activation of a toplevel window. | |
| CLEAR_GLOBAL_FOCUS_OWNER | back to summary |
|---|---|
| public static final FocusEvent. Clearing global focus owner. | |
| MOUSE_EVENT | back to summary |
|---|---|
| public static final FocusEvent. An activating mouse event. | |
| ROLLBACK | back to summary |
|---|---|
| public static final FocusEvent. Restoring focus after a focus request has been rejected. | |
| TRAVERSAL | back to summary |
|---|---|
| public static final FocusEvent. A focus traversal action with unspecified direction. | |
| TRAVERSAL_BACKWARD | back to summary |
|---|---|
| public static final FocusEvent. A backward focus traversal action. | |
| TRAVERSAL_DOWN | back to summary |
|---|---|
| public static final FocusEvent. A down-cycle focus traversal action. | |
| TRAVERSAL_FORWARD | back to summary |
|---|---|
| public static final FocusEvent. A forward focus traversal action. | |
| TRAVERSAL_UP | back to summary |
|---|---|
| public static final FocusEvent. An up-cycle focus traversal action. | |
| UNEXPECTED | back to summary |
|---|---|
| public static final FocusEvent. A system action causing an unexpected focus change. | |
| UNKNOWN | back to summary |
|---|---|
| public static final FocusEvent. The default value. | |
| Cause | back to summary |
|---|---|
| private Cause() | |
| valueOf | back to summary |
|---|---|
| public static FocusEvent. | |
| values | back to summary |
|---|---|
| public static FocusEvent. | |