Class DefaultKeyboardFocusManager
java.lang.Object
java.awt.KeyboardFocusManager
java.awt.DefaultKeyboardFocusManager
- All Implemented Interfaces:
KeyEventDispatcher, KeyEventPostProcessor
- Direct Known Subclasses:
FocusManager
public class DefaultKeyboardFocusManager extends KeyboardFocusManager
The default KeyboardFocusManager for AWT applications. Focus traversal is done in response to a Component's focus traversal keys, and using a Container's FocusTraversalPolicy.
Please see How to Use the Focus Subsystem, a section in The Java Tutorial, and the Focus Specification for more information.
- Since:
- 1.4
- See Also:
Field Summary
Fields declared in class KeyboardFocusManager
BACKWARD_TRAVERSAL_KEYS, DOWN_CYCLE_TRAVERSAL_KEYS, FORWARD_TRAVERSAL_KEYS, UP_CYCLE_TRAVERSAL_KEYS | Modifier and Type | Field | Description |
|---|---|---|
static final int |
BACKWARD_TRAVERSAL_KEYS |
The identifier for the Backward focus traversal keys. |
static final int |
DOWN_CYCLE_TRAVERSAL_KEYS |
The identifier for the Down Cycle focus traversal keys. |
static final int |
FORWARD_TRAVERSAL_KEYS |
The identifier for the Forward focus traversal keys. |
static final int |
UP_CYCLE_TRAVERSAL_KEYS |
The identifier for the Up Cycle focus traversal keys. |
Constructor Summary
| Constructor | Description |
|---|---|
DefaultKeyboardFocusManager() |
Constructs a DefaultKeyboardFocusManager. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
dequeueKeyEvents |
Releases for normal dispatching to the current focus owner all KeyEvents which were enqueued because of a call to enqueueKeyEvents with the same timestamp and Component. |
protected void |
discardKeyEvents |
Discards all KeyEvents which were enqueued because of one or more calls to enqueueKeyEvents with the specified Component, or one of its descendants. |
boolean |
dispatchEvent |
This method is called by the AWT event dispatcher requesting that the current KeyboardFocusManager dispatch the specified event on its behalf. |
boolean |
dispatchKeyEvent |
Called by dispatchEvent if no other KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or if no other KeyEventDispatchers are registered. |
void |
downFocusCycle |
Moves the focus down one focus traversal cycle. |
protected void |
enqueueKeyEvents |
Delays dispatching of KeyEvents until the specified Component becomes the focus owner. |
void |
focusNextComponent |
Focuses the Component after aComponent, typically based on a FocusTraversalPolicy. |
void |
focusPreviousComponent |
Focuses the Component before aComponent, typically based on a FocusTraversalPolicy. |
boolean |
postProcessKeyEvent |
This method will be called by dispatchKeyEvent. |
void |
processKeyEvent |
This method initiates a focus traversal operation if and only if the KeyEvent represents a focus traversal key for the specified focusedComponent. |
void |
upFocusCycle |
Moves the focus up one focus traversal cycle. |
Methods declared in class KeyboardFocusManager
addKeyEventDispatcher, addKeyEventPostProcessor, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clearFocusOwner, clearGlobalFocusOwner, downFocusCycle, firePropertyChange, fireVetoableChange, focusNextComponent, focusPreviousComponent, getActiveWindow, getCurrentFocusCycleRoot, getCurrentKeyboardFocusManager, getDefaultFocusTraversalKeys, getDefaultFocusTraversalPolicy, getFocusedWindow, getFocusOwner, getGlobalActiveWindow, getGlobalCurrentFocusCycleRoot, getGlobalFocusedWindow, getGlobalFocusOwner, getGlobalPermanentFocusOwner, getKeyEventDispatchers, getKeyEventPostProcessors, getPermanentFocusOwner, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, redispatchEvent, removeKeyEventDispatcher, removeKeyEventPostProcessor, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener, setCurrentKeyboardFocusManager, setDefaultFocusTraversalKeys, setDefaultFocusTraversalPolicy, setGlobalActiveWindow, setGlobalCurrentFocusCycleRoot, setGlobalFocusedWindow, setGlobalFocusOwner, setGlobalPermanentFocusOwner, upFocusCycle | Modifier and Type | Method | Description |
|---|---|---|
void |
addKeyEventDispatcher |
Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher chain. |
void |
addKeyEventPostProcessor |
Adds a KeyEventPostProcessor to this KeyboardFocusManager's post- processor chain. |
void |
addPropertyChangeListener |
Adds a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener |
Adds a PropertyChangeListener to the listener list for a specific property. |
void |
addVetoableChangeListener |
Adds a VetoableChangeListener to the listener list. |
void |
addVetoableChangeListener |
Adds a VetoableChangeListener to the listener list for a specific property. |
void |
clearFocusOwner() |
Clears the focus owner at both the Java and native levels if the focus owner exists and resides in the same context as the calling thread, otherwise the method returns silently. |
void |
clearGlobalFocusOwner() |
Clears the global focus owner at both the Java and native levels. |
final void |
downFocusCycle() |
Moves the focus down one focus traversal cycle from the current focus owner, if and only if the current focus owner is a Container that is a focus cycle root. |
protected void |
firePropertyChange |
Fires a PropertyChangeEvent in response to a change in a bound property. |
protected void |
fireVetoableChange |
Fires a PropertyChangeEvent in response to a change in a vetoable property. |
final void |
focusNextComponent() |
Focuses the Component after the current focus owner. |
final void |
focusPreviousComponent() |
Focuses the Component before the current focus owner. |
Window |
getActiveWindow() |
Returns the active Window. |
Container |
getCurrentFocusCycleRoot() |
Returns the current focus cycle root, if the current focus cycle root is in the same context as the calling thread. |
static KeyboardFocusManager |
getCurrentKeyboardFocusManager() |
Returns the current KeyboardFocusManager instance |
Set |
getDefaultFocusTraversalKeys |
Returns a Set of default focus traversal keys for a given traversal operation. |
FocusTraversalPolicy |
getDefaultFocusTraversalPolicy() |
Returns the default FocusTraversalPolicy. |
Window |
getFocusedWindow() |
Returns the focused Window. |
Component |
getFocusOwner() |
Returns the focus owner, if the focus owner is in the same context as the calling thread. |
protected Window |
getGlobalActiveWindow() |
Returns the active Window, even if the calling thread is in a different context than the active Window. |
protected Container |
getGlobalCurrentFocusCycleRoot() |
Returns the current focus cycle root, even if the calling thread is in a different context than the current focus cycle root. |
protected Window |
getGlobalFocusedWindow() |
Returns the focused Window, even if the calling thread is in a different context than the focused Window. |
protected Component |
getGlobalFocusOwner() |
Returns the focus owner, even if the calling thread is in a different context than the focus owner. |
protected Component |
getGlobalPermanentFocusOwner() |
Returns the permanent focus owner. |
protected List |
getKeyEventDispatchers() |
Returns this KeyboardFocusManager's KeyEventDispatcher chain as a List. |
protected List |
getKeyEventPostProcessors() |
Returns this KeyboardFocusManager's KeyEventPostProcessor chain as a List. |
Component |
getPermanentFocusOwner() |
Returns the permanent focus owner. |
PropertyChangeListener[] |
getPropertyChangeListeners() |
Returns an array of all the property change listeners registered on this keyboard focus manager. |
PropertyChangeListener[] |
getPropertyChangeListeners |
Returns an array of all the PropertyChangeListeners associated with the named property. |
VetoableChangeListener[] |
getVetoableChangeListeners() |
Returns an array of all the vetoable change listeners registered on this keyboard focus manager. |
VetoableChangeListener[] |
getVetoableChangeListeners |
Returns an array of all the VetoableChangeListeners associated with the named property. |
final void |
redispatchEvent |
Redispatches an AWTEvent in such a way that the AWT event dispatcher will not recursively request that the KeyboardFocusManager, or any installed KeyEventDispatchers, dispatch the event again. |
void |
removeKeyEventDispatcher |
Removes a KeyEventDispatcher which was previously added to this KeyboardFocusManager's dispatcher chain. |
void |
removeKeyEventPostProcessor |
Removes a previously added KeyEventPostProcessor from this KeyboardFocusManager's post-processor chain. |
void |
removePropertyChangeListener |
Removes a PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener |
Removes a PropertyChangeListener from the listener list for a specific property. |
void |
removeVetoableChangeListener |
Removes a VetoableChangeListener from the listener list. |
void |
removeVetoableChangeListener |
Removes a VetoableChangeListener from the listener list for a specific property. |
static void |
setCurrentKeyboardFocusManager |
Sets the current KeyboardFocusManager instance. |
void |
setDefaultFocusTraversalKeys |
Sets the default focus traversal keys for a given traversal operation. |
void |
setDefaultFocusTraversalPolicy |
Sets the default FocusTraversalPolicy. |
protected void |
setGlobalActiveWindow |
Sets the active Window. |
void |
setGlobalCurrentFocusCycleRoot |
Sets the current focus cycle root. |
protected void |
setGlobalFocusedWindow |
Sets the focused Window. |
protected void |
setGlobalFocusOwner |
Sets the focus owner. |
protected void |
setGlobalPermanentFocusOwner |
Sets the permanent focus owner. |
final void |
upFocusCycle() |
Moves the focus up one focus traversal cycle from the current focus owner. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
DefaultKeyboardFocusManager
public DefaultKeyboardFocusManager()
Constructs a
DefaultKeyboardFocusManager.Method Details
dispatchEvent
public boolean dispatchEvent(AWTEvent e)
This method is called by the AWT event dispatcher requesting that the current KeyboardFocusManager dispatch the specified event on its behalf. DefaultKeyboardFocusManagers dispatch all FocusEvents, all WindowEvents related to focus, and all KeyEvents. These events are dispatched based on the KeyboardFocusManager's notion of the focus owner and the focused and active Windows, sometimes overriding the source of the specified AWTEvent. If this method returns
false, then the AWT event dispatcher will attempt to dispatch the event itself.- Specified by:
-
dispatchEventin classKeyboardFocusManager - Parameters:
-
e- the AWTEvent to be dispatched - Returns:
-
trueif this method dispatched the event;falseotherwise - See Also:
dispatchKeyEvent
public boolean dispatchKeyEvent(KeyEvent e)
Called by
dispatchEvent if no other KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or if no other KeyEventDispatchers are registered. If the event has not been consumed, its target is enabled, and the focus owner is not null, this method dispatches the event to its target. This method will also subsequently dispatch the event to all registered KeyEventPostProcessors. After all this operations are finished, the event is passed to peers for processing. In all cases, this method returns true, since DefaultKeyboardFocusManager is designed so that neither dispatchEvent, nor the AWT event dispatcher, should take further action on the event in any situation.
- Specified by:
-
dispatchKeyEventin interfaceKeyEventDispatcher - Specified by:
-
dispatchKeyEventin classKeyboardFocusManager - Parameters:
-
e- the KeyEvent to be dispatched - Returns:
true- See Also:
postProcessKeyEvent
public boolean postProcessKeyEvent(KeyEvent e)
This method will be called by
dispatchKeyEvent. It will handle any unconsumed KeyEvents that map to an AWT MenuShortcut by consuming the event and activating the shortcut.- Specified by:
-
postProcessKeyEventin interfaceKeyEventPostProcessor - Specified by:
-
postProcessKeyEventin classKeyboardFocusManager - Parameters:
-
e- the KeyEvent to post-process - Returns:
true- See Also:
processKeyEvent
public void processKeyEvent(Component focusedComponent, KeyEvent e)
This method initiates a focus traversal operation if and only if the KeyEvent represents a focus traversal key for the specified focusedComponent. It is expected that focusedComponent is the current focus owner, although this need not be the case. If it is not, focus traversal will nevertheless proceed as if focusedComponent were the focus owner.
- Specified by:
-
processKeyEventin classKeyboardFocusManager - Parameters:
-
focusedComponent- the Component that is the basis for a focus traversal operation if the specified event represents a focus traversal key for the Component -
e- the event that may represent a focus traversal key
enqueueKeyEvents
protected void enqueueKeyEvents(long after, Component untilFocused)
Delays dispatching of KeyEvents until the specified Component becomes the focus owner. KeyEvents with timestamps later than the specified timestamp will be enqueued until the specified Component receives a FOCUS_GAINED event, or the AWT cancels the delay request by invoking
dequeueKeyEvents or discardKeyEvents.- Specified by:
-
enqueueKeyEventsin classKeyboardFocusManager - Parameters:
-
after- timestamp of current event, or the current, system time if the current event has no timestamp, or the AWT cannot determine which event is currently being handled -
untilFocused- Component which will receive a FOCUS_GAINED event before any pending KeyEvents - See Also:
dequeueKeyEvents
protected void dequeueKeyEvents(long after, Component untilFocused)
Releases for normal dispatching to the current focus owner all KeyEvents which were enqueued because of a call to
enqueueKeyEvents with the same timestamp and Component. If the given timestamp is less than zero, the outstanding enqueue request for the given Component with the oldest timestamp (if any) should be cancelled.- Specified by:
-
dequeueKeyEventsin classKeyboardFocusManager - Parameters:
-
after- the timestamp specified in the call toenqueueKeyEvents, or any value < 0 -
untilFocused- the Component specified in the call toenqueueKeyEvents - See Also:
discardKeyEvents
protected void discardKeyEvents(Component comp)
Discards all KeyEvents which were enqueued because of one or more calls to
enqueueKeyEvents with the specified Component, or one of its descendants.- Specified by:
-
discardKeyEventsin classKeyboardFocusManager - Parameters:
-
comp- the Component specified in one or more calls toenqueueKeyEvents, or a parent of such a Component - See Also:
focusPreviousComponent
public void focusPreviousComponent(Component aComponent)
Focuses the Component before aComponent, typically based on a FocusTraversalPolicy.
- Specified by:
-
focusPreviousComponentin classKeyboardFocusManager - Parameters:
-
aComponent- the Component that is the basis for the focus traversal operation - See Also:
focusNextComponent
public void focusNextComponent(Component aComponent)
Focuses the Component after aComponent, typically based on a FocusTraversalPolicy.
- Specified by:
-
focusNextComponentin classKeyboardFocusManager - Parameters:
-
aComponent- the Component that is the basis for the focus traversal operation - See Also:
upFocusCycle
public void upFocusCycle(Component aComponent)
Moves the focus up one focus traversal cycle. Typically, the focus owner is set to aComponent's focus cycle root, and the current focus cycle root is set to the new focus owner's focus cycle root. If, however, aComponent's focus cycle root is a Window, then the focus owner is set to the focus cycle root's default Component to focus, and the current focus cycle root is unchanged.
- Specified by:
-
upFocusCyclein classKeyboardFocusManager - Parameters:
-
aComponent- the Component that is the basis for the focus traversal operation - See Also:
downFocusCycle
public void downFocusCycle(Container aContainer)
Moves the focus down one focus traversal cycle. If aContainer is a focus cycle root, then the focus owner is set to aContainer's default Component to focus, and the current focus cycle root is set to aContainer. If aContainer is not a focus cycle root, then no focus traversal operation occurs.
- Specified by:
-
downFocusCyclein classKeyboardFocusManager - Parameters:
-
aContainer- the Container that is the basis for the focus traversal operation - See Also:
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.