KeyboardFocusManager.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:openjdk-jdk10 作者:
/**
 * Sets the permanent focus owner. The operation will be cancelled if the
 * Component is not focusable. The permanent focus owner is defined as the
 * last Component in an application to receive a permanent FOCUS_GAINED
 * event. The focus owner and permanent focus owner are equivalent unless
 * a temporary focus change is currently in effect. In such a situation,
 * the permanent focus owner will again be the focus owner when the
 * temporary focus change ends.
 * <p>
 * This method does not actually set the focus to the specified Component.
 * It merely stores the value to be subsequently returned by
 * {@code getPermanentFocusOwner()}. Use
 * {@code Component.requestFocus()} or
 * {@code Component.requestFocusInWindow()} to change the focus owner,
 * subject to platform limitations.
 *
 * @param permanentFocusOwner the permanent focus owner
 * @see #getPermanentFocusOwner
 * @see #getGlobalPermanentFocusOwner
 * @see Component#requestFocus()
 * @see Component#requestFocusInWindow()
 * @see Component#isFocusable
 * @throws SecurityException if this KeyboardFocusManager is not the
 *         current KeyboardFocusManager for the calling thread's context
 *         and if the calling thread does not have "replaceKeyboardFocusManager"
 *         permission
 */
protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner)
    throws SecurityException
{
    Component oldPermanentFocusOwner = null;
    boolean shouldFire = false;

    if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
        synchronized (KeyboardFocusManager.class) {
            checkKFMSecurity();

            oldPermanentFocusOwner = getPermanentFocusOwner();

            try {
                fireVetoableChange("permanentFocusOwner",
                                   oldPermanentFocusOwner,
                                   permanentFocusOwner);
            } catch (PropertyVetoException e) {
                // rejected
                return;
            }

            KeyboardFocusManager.permanentFocusOwner = permanentFocusOwner;

            KeyboardFocusManager.
                setMostRecentFocusOwner(permanentFocusOwner);

            shouldFire = true;
        }
    }

    if (shouldFire) {
        firePropertyChange("permanentFocusOwner", oldPermanentFocusOwner,
                           permanentFocusOwner);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号