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

public Class DefaultKeyboardFocusManager

extends KeyboardFocusManager
Class Inheritance
Known Direct Subclasses
javax.swing.FocusManager
Imports
java.awt.event.FocusEvent, .KeyEvent, .WindowEvent, java.awt.peer.ComponentPeer, .LightweightPeer, java.io.Serial, java.lang.ref.WeakReference, java.util.Iterator, .LinkedList, .ListIterator, .Set, sun.awt.AWTAccessor, .SunToolkit, .TimedWindowEvent, sun.util.logging.PlatformLogger

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.

Author
David Mendenhall
Since
1.4
See Also
FocusTraversalPolicy, Component#setFocusTraversalKeys, Component#getFocusTraversalKeys

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DefaultKeyboardFocusManager.DefaultKeyboardFocusManagerSentEvent

A special type of SentEvent which updates a counter in the target KeyboardFocusManager if it is an instance of DefaultKeyboardFocusManager.

private static class

Field Summary

Modifier and TypeField and Description
private boolean
private LinkedList<KeyEvent>
private static final PlatformLogger
private static boolean
private int
private static final WeakReference<Component>
private static final WeakReference<Window>
private WeakReference<Component>
private WeakReference<Window>
private Component
private LinkedList<DefaultKeyboardFocusManager.TypeAheadMarker>
Inherited from java.awt.KeyboardFocusManager:
BACKWARD_TRAVERSAL_KEYScurrentSequencedEventDOWN_CYCLE_TRAVERSAL_KEYSFORWARD_TRAVERSAL_KEYSpeerSNFH_FAILURESNFH_SUCCESS_HANDLEDSNFH_SUCCESS_PROCEEDTRAVERSAL_KEY_LENGTHUP_CYCLE_TRAVERSAL_KEYS

Constructor Summary

AccessConstructor and Description
public
DefaultKeyboardFocusManager()

Constructs a DefaultKeyboardFocusManager.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
private void
private boolean
private void
protected synchronized void
dequeueKeyEvents(long
the timestamp specified in the call to enqueueKeyEvents, or any value < 0
after
,
Component
the Component specified in the call to enqueueKeyEvents
untilFocused
)

Implements abstract java.awt.KeyboardFocusManager.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 synchronized void
discardKeyEvents(Component
the Component specified in one or more calls to enqueueKeyEvents, or a parent of such a Component
comp
)

Implements abstract java.awt.KeyboardFocusManager.discardKeyEvents.

Discards all KeyEvents which were enqueued because of one or more calls to enqueueKeyEvents with the specified Component, or one of its descendants.

public boolean

Returns:

true if this method dispatched the event; false otherwise
dispatchEvent
(AWTEvent
the AWTEvent to be dispatched
e
)

Implements abstract java.awt.KeyboardFocusManager.dispatchEvent.

This method is called by the AWT event dispatcher requesting that the current KeyboardFocusManager dispatch the specified event on its behalf.

public boolean

Returns:

true
dispatchKeyEvent
(KeyEvent
the KeyEvent to be dispatched
e
)

Implements abstract java.awt.KeyboardFocusManager.dispatchKeyEvent.

Implements java.awt.KeyEventDispatcher.dispatchKeyEvent.

Called by dispatchEvent if no other KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or if no other KeyEventDispatchers are registered.

private boolean
doRestoreFocus(Component toFocus, Component vetoedComponent, boolean clearOnFailure)

public void
downFocusCycle(Container
the Container that is the basis for the focus traversal operation
aContainer
)

Implements abstract java.awt.KeyboardFocusManager.downFocusCycle.

Moves the focus down one focus traversal cycle.

pack-priv void
dumpMarkers()

Dumps the list of type-ahead queue markers to stderr

protected synchronized void
enqueueKeyEvents(long
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
after
,
Component
Component which will receive a FOCUS_GAINED event before any pending KeyEvents
untilFocused
)

Implements abstract java.awt.KeyboardFocusManager.enqueueKeyEvents.

Delays dispatching of KeyEvents until the specified Component becomes the focus owner.

public void
focusNextComponent(Component
the Component that is the basis for the focus traversal operation
aComponent
)

Implements abstract java.awt.KeyboardFocusManager.focusNextComponent.

Focuses the Component after aComponent, typically based on a FocusTraversalPolicy.

public void
focusPreviousComponent(Component
the Component that is the basis for the focus traversal operation
aComponent
)

Implements abstract java.awt.KeyboardFocusManager.focusPreviousComponent.

Focuses the Component before aComponent, typically based on a FocusTraversalPolicy.

private Window
private boolean
hasMarker(Component comp)

Returns true if there are some marker associated with component comp in a markers' queue

private static void
public boolean

Returns:

true
postProcessKeyEvent
(KeyEvent
the KeyEvent to post-process
e
)

Implements abstract java.awt.KeyboardFocusManager.postProcessKeyEvent.

Implements java.awt.KeyEventPostProcessor.postProcessKeyEvent.

This method will be called by dispatchKeyEvent.

private boolean
public void
processKeyEvent(Component
the Component that is the basis for a focus traversal operation if the specified event represents a focus traversal key for the Component
focusedComponent
,
KeyEvent
the event that may represent a focus traversal key
e
)

Implements abstract java.awt.KeyboardFocusManager.processKeyEvent.

This method initiates a focus traversal operation if and only if the KeyEvent represents a focus traversal key for the specified focusedComponent.

private void
private void
purgeStampedEvents(long start, long end)

private boolean
private void
restoreFocus(FocusEvent fe, Window newFocusedWindow)

private void
private boolean
restoreFocus(Window aWindow, Component vetoedComponent, boolean clearOnFailure)

private boolean
restoreFocus(Component toFocus, boolean clearOnFailure)

pack-priv static boolean
sendMessage(Component target, AWTEvent e)

Sends a synthetic AWTEvent to a Component.

private boolean
public void
upFocusCycle(Component
the Component that is the basis for the focus traversal operation
aComponent
)

Implements abstract java.awt.KeyboardFocusManager.upFocusCycle.

Moves the focus up one focus traversal cycle.

Inherited from java.awt.KeyboardFocusManager:
addKeyEventDispatcheraddKeyEventPostProcessoraddPropertyChangeListeneraddPropertyChangeListeneraddVetoableChangeListeneraddVetoableChangeListenerclearFocusOwnerclearGlobalFocusOwnerclearGlobalFocusOwnerPrivclearMostRecentFocusOwnerdownFocusCycledumpRequestsfirePropertyChangefireVetoableChangefocusNextComponentfocusPreviousComponentgetActiveWindowgetCurrentFocusCycleRootgetCurrentKeyboardFocusManagergetCurrentSequencedEventgetCurrentWaitingRequestgetDefaultFocusTraversalKeysgetDefaultFocusTraversalPolicygetFocusedWindowgetFocusOwnergetGlobalActiveWindowgetGlobalCurrentFocusCycleRootgetGlobalFocusedWindowgetGlobalFocusOwnergetGlobalPermanentFocusOwnergetHeavyweightgetKeyEventDispatchersgetKeyEventPostProcessorsgetMostRecentFocusOwnergetNativeFocusedWindowgetNativeFocusOwnergetPermanentFocusOwnergetPropertyChangeListenersgetPropertyChangeListenersgetVetoableChangeListenersgetVetoableChangeListenersinitFocusTraversalKeysSetisAutoFocusTransferEnabledisAutoFocusTransferEnabledForisProxyActivemarkClearGlobalFocusOwnerprocessCurrentLightweightRequestsprocessSynchronousLightweightTransferredispatchEventremoveFirstRequestremoveKeyEventDispatcherremoveKeyEventPostProcessorremoveLastFocusRequestremovePropertyChangeListenerremovePropertyChangeListenerremoveVetoableChangeListenerremoveVetoableChangeListenerretargetFocusEventretargetFocusGainedretargetFocusLostretargetUnexpectedFocusEventsetCurrentKeyboardFocusManagersetCurrentSequencedEventsetDefaultFocusTraversalKeyssetDefaultFocusTraversalPolicysetGlobalActiveWindowsetGlobalCurrentFocusCycleRootsetGlobalCurrentFocusCycleRootPrivsetGlobalFocusedWindowsetGlobalFocusOwnersetGlobalPermanentFocusOwnersetMostRecentFocusOwnersetMostRecentFocusOwnersetNativeFocusOwnershouldNativelyFocusHeavyweightupFocusCycle

Field Detail

consumeNextKeyTypedback to summary
private boolean consumeNextKeyTyped
enqueuedKeyEventsback to summary
private LinkedList<KeyEvent> enqueuedKeyEvents
focusLogback to summary
private static final PlatformLogger focusLog

Hides java.awt.KeyboardFocusManager.focusLog.

fxAppThreadIsDispatchThreadback to summary
private static boolean fxAppThreadIsDispatchThread
inSendMessageback to summary
private int inSendMessage
NULL_COMPONENT_WRback to summary
private static final WeakReference<Component> NULL_COMPONENT_WR
NULL_WINDOW_WRback to summary
private static final WeakReference<Window> NULL_WINDOW_WR
realOppositeComponentWRback to summary
private WeakReference<Component> realOppositeComponentWR
realOppositeWindowWRback to summary
private WeakReference<Window> realOppositeWindowWR
restoreFocusToback to summary
private Component restoreFocusTo
typeAheadMarkersback to summary
private LinkedList<DefaultKeyboardFocusManager.TypeAheadMarker> typeAheadMarkers

Constructor Detail

DefaultKeyboardFocusManagerback to summary
public DefaultKeyboardFocusManager()

Constructs a DefaultKeyboardFocusManager.

Method Detail

clearMarkersback to summary
pack-priv void clearMarkers()

Overrides java.awt.KeyboardFocusManager.clearMarkers.

Clears markers queue

Since
1.5
consumeNextKeyTypedback to summary
private void consumeNextKeyTyped(KeyEvent e)
consumeProcessedKeyEventback to summary
private boolean consumeProcessedKeyEvent(KeyEvent e)
consumeTraversalKeyback to summary
private void consumeTraversalKey(KeyEvent e)
dequeueKeyEventsback to summary
protected synchronized void dequeueKeyEvents(long after, Component untilFocused)

Implements abstract java.awt.KeyboardFocusManager.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. 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.

Parameters
after:long

the timestamp specified in the call to enqueueKeyEvents, or any value < 0

untilFocused:Component

the Component specified in the call to enqueueKeyEvents

See Also
enqueueKeyEvents, discardKeyEvents
discardKeyEventsback to summary
protected synchronized void discardKeyEvents(Component comp)

Implements abstract java.awt.KeyboardFocusManager.discardKeyEvents.

Discards all KeyEvents which were enqueued because of one or more calls to enqueueKeyEvents with the specified Component, or one of its descendants.

Parameters
comp:Component

the Component specified in one or more calls to enqueueKeyEvents, or a parent of such a Component

See Also
enqueueKeyEvents, dequeueKeyEvents
dispatchEventback to summary
public boolean dispatchEvent(AWTEvent e)

Implements abstract java.awt.KeyboardFocusManager.dispatchEvent.

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.

Parameters
e:AWTEvent

the AWTEvent to be dispatched

Returns:boolean

true if this method dispatched the event; false otherwise

dispatchKeyEventback to summary
public boolean dispatchKeyEvent(KeyEvent e)

Implements abstract java.awt.KeyboardFocusManager.dispatchKeyEvent.

Implements java.awt.KeyEventDispatcher.dispatchKeyEvent.

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.

Parameters
e:KeyEvent

the KeyEvent to be dispatched

Returns:boolean

true

See Also
Component#dispatchEvent
doRestoreFocusback to summary
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent, boolean clearOnFailure)
downFocusCycleback to summary
public void downFocusCycle(Container aContainer)

Implements abstract java.awt.KeyboardFocusManager.downFocusCycle.

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.

Parameters
aContainer:Container

the Container that is the basis for the focus traversal operation

See Also
Container#transferFocusDownCycle
dumpMarkersback to summary
pack-priv void dumpMarkers()

Dumps the list of type-ahead queue markers to stderr

enqueueKeyEventsback to summary
protected synchronized void enqueueKeyEvents(long after, Component untilFocused)

Implements abstract java.awt.KeyboardFocusManager.enqueueKeyEvents.

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.

Parameters
after:long

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

Component which will receive a FOCUS_GAINED event before any pending KeyEvents

See Also
dequeueKeyEvents, discardKeyEvents
focusNextComponentback to summary
public void focusNextComponent(Component aComponent)

Implements abstract java.awt.KeyboardFocusManager.focusNextComponent.

Focuses the Component after aComponent, typically based on a FocusTraversalPolicy.

Parameters
aComponent:Component

the Component that is the basis for the focus traversal operation

See Also
FocusTraversalPolicy, Component#transferFocus
focusPreviousComponentback to summary
public void focusPreviousComponent(Component aComponent)

Implements abstract java.awt.KeyboardFocusManager.focusPreviousComponent.

Focuses the Component before aComponent, typically based on a FocusTraversalPolicy.

Parameters
aComponent:Component

the Component that is the basis for the focus traversal operation

See Also
FocusTraversalPolicy, Component#transferFocusBackward
getOwningFrameDialogback to summary
private Window getOwningFrameDialog(Window window)
hasMarkerback to summary
private boolean hasMarker(Component comp)

Returns true if there are some marker associated with component comp in a markers' queue

Since
1.5
initStaticback to summary
private static void initStatic()
postProcessKeyEventback to summary
public boolean postProcessKeyEvent(KeyEvent e)

Implements abstract java.awt.KeyboardFocusManager.postProcessKeyEvent.

Implements java.awt.KeyEventPostProcessor.postProcessKeyEvent.

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.

Parameters
e:KeyEvent

the KeyEvent to post-process

Returns:boolean

true

See Also
dispatchKeyEvent, MenuShortcut
preDispatchKeyEventback to summary
private boolean preDispatchKeyEvent(KeyEvent ke)
processKeyEventback to summary
public void processKeyEvent(Component focusedComponent, KeyEvent e)

Implements abstract java.awt.KeyboardFocusManager.processKeyEvent.

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.

Parameters
focusedComponent:Component

the Component that is the basis for a focus traversal operation if the specified event represents a focus traversal key for the Component

e:KeyEvent

the event that may represent a focus traversal key

pumpApprovedKeyEventsback to summary
private void pumpApprovedKeyEvents()
purgeStampedEventsback to summary
private void purgeStampedEvents(long start, long end)
repostIfFollowsKeyEventsback to summary
private boolean repostIfFollowsKeyEvents(WindowEvent e)
restoreFocusback to summary
private void restoreFocus(FocusEvent fe, Window newFocusedWindow)
restoreFocusback to summary
private void restoreFocus(WindowEvent we)
restoreFocusback to summary
private boolean restoreFocus(Window aWindow, Component vetoedComponent, boolean clearOnFailure)
restoreFocusback to summary
private boolean restoreFocus(Component toFocus, boolean clearOnFailure)
sendMessageback to summary
pack-priv static boolean sendMessage(Component target, AWTEvent e)

Sends a synthetic AWTEvent to a Component.

typeAheadAssertionsback to summary
private boolean typeAheadAssertions(Component target, AWTEvent e)
upFocusCycleback to summary
public void upFocusCycle(Component aComponent)

Implements abstract java.awt.KeyboardFocusManager.upFocusCycle.

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.

Parameters
aComponent:Component

the Component that is the basis for the focus traversal operation

See Also
Component#transferFocusUpCycle
java.awt back to summary

private Class DefaultKeyboardFocusManager.DefaultKeyboardFocusManagerSentEvent

extends SentEvent
Class Inheritance

A special type of SentEvent which updates a counter in the target KeyboardFocusManager if it is an instance of DefaultKeyboardFocusManager.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.awt.SentEvent.serialVersionUID.

Use serialVersionUID from JDK 1.6 for interoperability.
Inherited from java.awt.SentEvent:
dispatchedID

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final void
dispatch()

Overrides java.awt.SentEvent.dispatch.

Implements java.awt.ActiveEvent.dispatch.

Dispatch the event to its target, listeners of the events source, or do whatever it is this event is supposed to do.

Inherited from java.awt.SentEvent:
dispose

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.SentEvent.serialVersionUID.

Use serialVersionUID from JDK 1.6 for interoperability.

Annotations
@Serial

Constructor Detail

DefaultKeyboardFocusManagerSentEventback to summary
public DefaultKeyboardFocusManagerSentEvent(AWTEvent nested)

Method Detail

dispatchback to summary
public final void dispatch()

Overrides java.awt.SentEvent.dispatch.

Implements java.awt.ActiveEvent.dispatch.

Doc from java.awt.ActiveEvent.dispatch.

Dispatch the event to its target, listeners of the events source, or do whatever it is this event is supposed to do.

java.awt back to summary

private Class DefaultKeyboardFocusManager.TypeAheadMarker

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv Component

Constructor Summary

AccessConstructor and Description
pack-priv
TypeAheadMarker(long after, Component untilFocused)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns string representation of the marker

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

afterback to summary
pack-priv long after
untilFocusedback to summary
pack-priv Component untilFocused

Constructor Detail

TypeAheadMarkerback to summary
pack-priv TypeAheadMarker(long after, Component untilFocused)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns string representation of the marker