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

public abstract Class KeyboardFocusManager

extends Object
implements KeyEventDispatcher, KeyEventPostProcessor
Class Inheritance
All Implemented Interfaces
java.awt.KeyEventPostProcessor, java.awt.KeyEventDispatcher
Known Direct Subclasses
java.awt.DefaultKeyboardFocusManager
Imports
java.awt.event.FocusEvent, .InputEvent, .KeyEvent, .WindowEvent, java.awt.peer.KeyboardFocusManagerPeer, .LightweightPeer, java.beans.PropertyChangeListener, .PropertyChangeSupport, .PropertyVetoException, .VetoableChangeListener, .VetoableChangeSupport, java.lang.ref.WeakReference, java.util.Collections, .HashSet, .Iterator, .LinkedList, .Set, .StringTokenizer, .WeakHashMap, sun.util.logging.PlatformLogger, sun.awt.SunToolkit, .KeyboardFocusManagerPeerProvider, .AWTAccessor

The KeyboardFocusManager is responsible for managing the active and focused Windows, and the current focus owner. The focus owner is defined as the Component in an application that will typically receive all KeyEvents generated by the user. The focused Window is the Window that is, or contains, the focus owner. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

The KeyboardFocusManager is both a centralized location for client code to query for the focus owner and initiate focus changes, and an event dispatcher for all FocusEvents, WindowEvents related to focus, and KeyEvents.

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
Window, Frame, Dialog, java.awt.event.FocusEvent, java.awt.event.WindowEvent, java.awt.event.KeyEvent

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static Window
activeWindow

Only a Frame or a Dialog can be the active Window.

private static boolean
public static final int
BACKWARD_TRAVERSAL_KEYS

The identifier for the Backward focus traversal keys.

private PropertyChangeSupport
changeSupport

A description of any PropertyChangeListeners which have been registered.

private static boolean
private static Container
currentFocusCycleRoot

The current focus cycle root.

private static LinkedList<KeyboardFocusManager.LightweightFocusRequest>
pack-priv transient SequencedEvent
private static final String[]
defaultFocusTraversalKeyPropertyNames

The bound property names of each focus traversal key.

private Set<AWTKeyStroke>[]
defaultFocusTraversalKeys

The default focus traversal keys.

private FocusTraversalPolicy
defaultPolicy

The default FocusTraversalPolicy for all Windows that have no policy of their own set.

private static volatile boolean
public static final int
DOWN_CYCLE_TRAVERSAL_KEYS

The identifier for the Down Cycle focus traversal keys.

private static Window
focusedWindow

The Window which is, or contains, the focus owner.

private static final PlatformLogger
private static Component
focusOwner

The Component in an application that will typically receive all KeyEvents generated by the user.

public static final int
FORWARD_TRAVERSAL_KEYS

The identifier for the Forward focus traversal keys.

private static LinkedList<KeyboardFocusManager.HeavyweightFocusRequest>
private LinkedList<KeyEventDispatcher>
keyEventDispatchers

This KeyboardFocusManager's KeyEventDispatcher chain.

private LinkedList<KeyEventPostProcessor>
keyEventPostProcessors

This KeyboardFocusManager's KeyEventPostProcessor chain.

private static final PlatformLogger
private static KeyboardFocusManager
private static Map<Window, WeakReference<Component>>
mostRecentFocusOwners

Maps Windows to those Windows' most recent focus owners.

private static Component
pack-priv transient KeyboardFocusManagerPeer
private static Component
permanentFocusOwner

The Component in an application that will regain focus when an outstanding temporary focus transfer has completed, or the focus owner, if no outstanding temporary transfer exists.

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
public static final int
UP_CYCLE_TRAVERSAL_KEYS

The identifier for the Up Cycle focus traversal keys.

private VetoableChangeSupport
vetoableSupport

A description of any VetoableChangeListeners which have been registered.

Constructor Summary

AccessConstructor and Description
public
KeyboardFocusManager()

Initializes a KeyboardFocusManager.

Method Summary

Modifier and TypeMethod and Description
private void
public void
addKeyEventDispatcher(KeyEventDispatcher
the KeyEventDispatcher to add to the dispatcher chain
dispatcher
)

Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher chain.

public void
addKeyEventPostProcessor(KeyEventPostProcessor
the KeyEventPostProcessor to add to the post-processor chain
processor
)

Adds a KeyEventPostProcessor to this KeyboardFocusManager's post- processor chain.

public void
addPropertyChangeListener(PropertyChangeListener
the PropertyChangeListener to be added
listener
)

Adds a PropertyChangeListener to the listener list.

public void
addPropertyChangeListener(String
one of the property names listed above
propertyName
,
PropertyChangeListener
the PropertyChangeListener to be added
listener
)

Adds a PropertyChangeListener to the listener list for a specific property.

public void
addVetoableChangeListener(VetoableChangeListener
the VetoableChangeListener to be added
listener
)

Adds a VetoableChangeListener to the listener list.

public void
addVetoableChangeListener(String
one of the property names listed above
propertyName
,
VetoableChangeListener
the VetoableChangeListener to be added
listener
)

Adds a VetoableChangeListener to the listener list for a specific property.

public 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.

public void
clearGlobalFocusOwner()

Clears the global focus owner at both the Java and native levels.

pack-priv void
pack-priv void
clearMarkers()

Clears markers queue This method is not intended to be overridden by KFM's.

pack-priv static void
protected abstract 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
)

Called by the AWT to notify the KeyboardFocusManager that it should cancel delayed dispatching of KeyEvents.

protected abstract void
discardKeyEvents(Component
the Component specified in one or more calls to enqueueKeyEvents
comp
)

Called by the AWT to notify the KeyboardFocusManager that it should cancel delayed dispatching of KeyEvents.

private static Throwable
public abstract boolean

Returns:

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

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

public abstract boolean

Returns:

true if the KeyEvent was dispatched; false otherwise
dispatchKeyEvent
(KeyEvent
the KeyEvent which the current KeyboardFocusManager has requested that this KeyEventDispatcher dispatch
e
)

Redeclares java.awt.KeyEventDispatcher.dispatchKeyEvent.

Typically this method will be called by dispatchEvent if no other KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or if no other KeyEventDispatchers are registered.

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

Moves the focus down one focus traversal cycle.

public 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.

pack-priv void
dumpRequests()

Dumps the list of focus requests to stderr

protected abstract 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 should receive a FOCUS_GAINED event before any pending KeyEvents
untilFocused
)

Called by the AWT to notify the KeyboardFocusManager that it should delay dispatching of KeyEvents until the specified Component becomes the focus owner.

protected void
firePropertyChange(String
the name of the property that has changed
propertyName
,
Object
the property's previous value
oldValue
,
Object
the property's new value
newValue
)

Fires a PropertyChangeEvent in response to a change in a bound property.

protected void
fireVetoableChange(String
the name of the property that has changed
propertyName
,
Object
the property's previous value
oldValue
,
Object
the property's new value
newValue
)

Fires a PropertyChangeEvent in response to a change in a vetoable property.

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

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

public final void
focusNextComponent()

Focuses the Component after the current focus owner.

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

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

public final void
focusPreviousComponent()

Focuses the Component before the current focus owner.

public Window

Returns:

the active Window, or null if there is none
getActiveWindow
()

Returns the active Window.

public Container

Returns:

the current focus cycle root, or null if the current focus cycle root is not a member of the calling thread's context
getCurrentFocusCycleRoot
()

Returns the current focus cycle root, if the current focus cycle root is in the same context as the calling thread.

public static synchronized KeyboardFocusManager

Returns:

the current KeyboardFocusManager
getCurrentKeyboardFocusManager
()

Returns the current KeyboardFocusManager instance

pack-priv final SequencedEvent
pack-priv Component
public Set<AWTKeyStroke>

Returns:

the Set of AWTKeyStrokes for the specified operation; the Set will be unmodifiable, and may be empty; null will never be returned
getDefaultFocusTraversalKeys
(int
one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
id
)

Returns a Set of default focus traversal keys for a given traversal operation.

public synchronized FocusTraversalPolicy

Returns:

the default FocusTraversalPolicy. null will never be returned.
getDefaultFocusTraversalPolicy
()

Returns the default FocusTraversalPolicy.

private static KeyboardFocusManager.HeavyweightFocusRequest
public Window

Returns:

the focused Window, or null if there is none
getFocusedWindow
()

Returns the focused Window.

public Component

Returns:

the focus owner, or null if the focus owner is not a member of the calling thread's context
getFocusOwner
()

Returns the focus owner, if the focus owner is in the same context as the calling thread.

protected Window

Returns:

the active Window
getGlobalActiveWindow
()

Returns the active Window, even if the calling thread is in a different context than the active Window.

protected Container

Returns:

the current focus cycle root, or null if the current focus cycle root is not a member of the calling thread's context
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

Returns:

the focused Window
getGlobalFocusedWindow
()

Returns the focused Window, even if the calling thread is in a different context than the focused Window.

protected Component

Returns:

the focus owner
getGlobalFocusOwner
()

Returns the focus owner, even if the calling thread is in a different context than the focus owner.

protected Component

Returns:

the permanent focus owner, or null if there is none
getGlobalPermanentFocusOwner
()

Returns the permanent focus owner.

pack-priv static Component
protected synchronized List<KeyEventDispatcher>

Returns:

a possibly null or empty List of KeyEventDispatchers
getKeyEventDispatchers
()

Returns this KeyboardFocusManager's KeyEventDispatcher chain as a List.

protected List<KeyEventPostProcessor>

Returns:

a possibly null or empty List of KeyEventPostProcessors
getKeyEventPostProcessors
()

Returns this KeyboardFocusManager's KeyEventPostProcessor chain as a List.

private static KeyboardFocusManager.HeavyweightFocusRequest
pack-priv static synchronized Component
pack-priv Window
pack-priv Component
public Component

Returns:

the permanent focus owner, or null if there is none
getPermanentFocusOwner
()

Returns the permanent focus owner.

public synchronized PropertyChangeListener[]

Returns:

all of this keyboard focus manager's PropertyChangeListeners or an empty array if no property change listeners are currently registered
getPropertyChangeListeners
()

Returns an array of all the property change listeners registered on this keyboard focus manager.

public synchronized PropertyChangeListener[]

Returns:

all of the PropertyChangeListeners associated with the named property or an empty array if no such listeners have been added.
getPropertyChangeListeners
(String
the property name
propertyName
)

Returns an array of all the PropertyChangeListeners associated with the named property.

public synchronized VetoableChangeListener[]

Returns:

all of this keyboard focus manager's VetoableChangeListeners or an empty array if no vetoable change listeners are currently registered
getVetoableChangeListeners
()

Returns an array of all the vetoable change listeners registered on this keyboard focus manager.

public synchronized VetoableChangeListener[]

Returns:

all of the VetoableChangeListeners associated with the named property or an empty array if no such listeners have been added.
getVetoableChangeListeners
(String
the property name
propertyName
)

Returns an array of all the VetoableChangeListeners associated with the named property.

private static void
pack-priv static Set<AWTKeyStroke>
private void
pack-priv static boolean
pack-priv static boolean
pack-priv static boolean
private static boolean
private static boolean
pack-priv static Window
markClearGlobalFocusOwner()

Returns the Window which will be active after processing this request, or null if this is a duplicate request.

public abstract boolean

Returns:

true to indicate that no other KeyEventPostProcessor will be notified of the KeyEvent.
postProcessKeyEvent
(KeyEvent
the KeyEvent to post-process
e
)

Redeclares java.awt.KeyEventPostProcessor.postProcessKeyEvent.

This method will be called by dispatchKeyEvent.

pack-priv static void
public abstract void
processKeyEvent(Component
the Component that will be 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
)

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

pack-priv static boolean
processSynchronousLightweightTransfer(Component heavyweight, Component descendant, boolean temporary, boolean focusedWindowChangeAllowed, long time)

public final void
redispatchEvent(Component
the Component to which the event should be dispatched
target
,
AWTEvent
the event to dispatch
e
)

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.

pack-priv static boolean
public void
removeKeyEventDispatcher(KeyEventDispatcher
the KeyEventDispatcher to remove from the dispatcher chain
dispatcher
)

Removes a KeyEventDispatcher which was previously added to this KeyboardFocusManager's dispatcher chain.

public void
removeKeyEventPostProcessor(KeyEventPostProcessor
the KeyEventPostProcessor to remove from the post- processor chain
processor
)

Removes a previously added KeyEventPostProcessor from this KeyboardFocusManager's post-processor chain.

pack-priv static void
public void
removePropertyChangeListener(PropertyChangeListener
the PropertyChangeListener to be removed
listener
)

Removes a PropertyChangeListener from the listener list.

public void
removePropertyChangeListener(String
a valid property name
propertyName
,
PropertyChangeListener
the PropertyChangeListener to be removed
listener
)

Removes a PropertyChangeListener from the listener list for a specific property.

public void
removeVetoableChangeListener(VetoableChangeListener
the VetoableChangeListener to be removed
listener
)

Removes a VetoableChangeListener from the listener list.

public void
removeVetoableChangeListener(String
a valid property name
propertyName
,
VetoableChangeListener
the VetoableChangeListener to be removed
listener
)

Removes a VetoableChangeListener from the listener list for a specific property.

pack-priv static AWTEvent
pack-priv static FocusEvent
pack-priv static FocusEvent
pack-priv static FocusEvent
public static void
setCurrentKeyboardFocusManager(KeyboardFocusManager
the new KeyboardFocusManager
newManager
)

Sets the current KeyboardFocusManager instance.

pack-priv final void
public void
setDefaultFocusTraversalKeys(int
one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
id
,
Set<? extends AWTKeyStroke>
the Set of AWTKeyStrokes for the specified operation
keystrokes
)

Sets the default focus traversal keys for a given traversal operation.

public void
setDefaultFocusTraversalPolicy(FocusTraversalPolicy
the new, default FocusTraversalPolicy
defaultPolicy
)

Sets the default FocusTraversalPolicy.

protected void
setGlobalActiveWindow(Window
the active Window
activeWindow
)

Sets the active Window.

public void
setGlobalCurrentFocusCycleRoot(Container
the new focus cycle root
newFocusCycleRoot
)

Sets the current focus cycle root.

pack-priv void
protected void
setGlobalFocusedWindow(Window
the focused Window
focusedWindow
)

Sets the focused Window.

protected void
setGlobalFocusOwner(Component
the focus owner
focusOwner
)

Sets the focus owner.

protected void
setGlobalPermanentFocusOwner(Component
the permanent focus owner
permanentFocusOwner
)

Sets the permanent focus owner.

pack-priv static void
pack-priv static synchronized void
pack-priv void
pack-priv static int
shouldNativelyFocusHeavyweight(Component heavyweight, Component descendant, boolean temporary, boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause)

Indicates whether the native implementation should proceed with a pending, native focus request.

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

Moves the focus up one focus traversal cycle.

public final void
upFocusCycle()

Moves the focus up one focus traversal cycle from the current focus owner.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait