src/share/classes/java/awt/Component.java

Print this page




7905     boolean transferFocusBackward(boolean clearOnFailure) {
7906         Container rootAncestor = getTraversalRoot();
7907         Component comp = this;
7908         while (rootAncestor != null &&
7909                !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
7910         {
7911             comp = rootAncestor;
7912             rootAncestor = comp.getFocusCycleRootAncestor();
7913         }
7914         boolean res = false;
7915         if (rootAncestor != null) {
7916             FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
7917             Component toFocus = policy.getComponentBefore(rootAncestor, comp);
7918             if (toFocus == null) {
7919                 toFocus = policy.getDefaultComponent(rootAncestor);
7920             }
7921             if (toFocus != null) {
7922                 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
7923             }
7924         }
7925         if (!res) {
7926             if (focusLog.isLoggable(PlatformLogger.FINER)) {
7927                 focusLog.finer("clear global focus owner");
7928             }
7929             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
7930         }
7931         if (focusLog.isLoggable(PlatformLogger.FINER)) {
7932             focusLog.finer("returning result: " + res);
7933         }
7934         return res;
7935     }
7936 
7937     /**
7938      * Transfers the focus up one focus traversal cycle. Typically, the focus
7939      * owner is set to this Component's focus cycle root, and the current focus
7940      * cycle root is set to the new focus owner's focus cycle root. If,
7941      * however, this Component's focus cycle root is a Window, then the focus
7942      * owner is set to the focus cycle root's default Component to focus, and
7943      * the current focus cycle root is unchanged.
7944      *
7945      * @see       #requestFocus()




7905     boolean transferFocusBackward(boolean clearOnFailure) {
7906         Container rootAncestor = getTraversalRoot();
7907         Component comp = this;
7908         while (rootAncestor != null &&
7909                !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
7910         {
7911             comp = rootAncestor;
7912             rootAncestor = comp.getFocusCycleRootAncestor();
7913         }
7914         boolean res = false;
7915         if (rootAncestor != null) {
7916             FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
7917             Component toFocus = policy.getComponentBefore(rootAncestor, comp);
7918             if (toFocus == null) {
7919                 toFocus = policy.getDefaultComponent(rootAncestor);
7920             }
7921             if (toFocus != null) {
7922                 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
7923             }
7924         }
7925         if (clearOnFailure && !res) {
7926             if (focusLog.isLoggable(PlatformLogger.FINER)) {
7927                 focusLog.finer("clear global focus owner");
7928             }
7929             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
7930         }
7931         if (focusLog.isLoggable(PlatformLogger.FINER)) {
7932             focusLog.finer("returning result: " + res);
7933         }
7934         return res;
7935     }
7936 
7937     /**
7938      * Transfers the focus up one focus traversal cycle. Typically, the focus
7939      * owner is set to this Component's focus cycle root, and the current focus
7940      * cycle root is set to the new focus owner's focus cycle root. If,
7941      * however, this Component's focus cycle root is a Window, then the focus
7942      * owner is set to the focus cycle root's default Component to focus, and
7943      * the current focus cycle root is unchanged.
7944      *
7945      * @see       #requestFocus()