Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. This component must be displayable, focusable, visible and all of its ancestors (with the exception of the top-level Window) must be visible for the request to be granted. Every effort will be made to honor the request; however, in some cases it may be impossible to do so. Developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event.
This method returns a boolean value. If false
is returned, the request is guaranteed to fail. If true
is returned, the request will succeed unless it is vetoed, or an extraordinary event, such as disposal of the Component's peer, occurs before the request can be granted by the native windowing system. Again, while a return value of true
indicates that the request is likely to succeed, developers must never assume that this Component is the focus owner until this Component receives a FOCUS_GAINED event.
This method cannot be used to set the focus owner to no Component at all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
The focus behavior of this method can be implemented uniformly across platforms, and thus developers are strongly encouraged to use this method over requestFocus
when possible. Code which relies on requestFocus
may exhibit different focus behavior on different platforms.
Note: Not all focus transfers result from invoking this method. As such, a component may receive focus without this or any of the other {@code requestFocus} methods of {@code Component} being invoked.
@return false
if the focus change request is guaranteed tofail; true
if it is likely to succeed
@see #requestFocus
@see java.awt.event.FocusEvent
@see #addFocusListener
@see #isFocusable
@see #isDisplayable
@see KeyboardFocusManager#clearGlobalFocusOwner
@since 1.4