7509 */ |
7509 */ |
7510 public void requestFocus() { |
7510 public void requestFocus() { |
7511 requestFocusHelper(false, true); |
7511 requestFocusHelper(false, true); |
7512 } |
7512 } |
7513 |
7513 |
7514 boolean requestFocus(FocusEvent.Cause cause) { |
7514 |
7515 return requestFocusHelper(false, true, cause); |
7515 /** |
|
7516 * Requests by the reason of {@code cause} that this Component get the input |
|
7517 * focus, and that this Component's top-level ancestor become the |
|
7518 * focused Window. This component must be displayable, focusable, visible |
|
7519 * and all of its ancestors (with the exception of the top-level Window) |
|
7520 * must be visible for the request to be granted. Every effort will be |
|
7521 * made to honor the request; however, in some cases it may be |
|
7522 * impossible to do so. Developers must never assume that this |
|
7523 * Component is the focus owner until this Component receives a |
|
7524 * FOCUS_GAINED event. |
|
7525 * <p> |
|
7526 * The focus request effect may also depend on the provided |
|
7527 * cause value. If this request is succeed the {@code FocusEvent} |
|
7528 * generated in the result will receive the cause value specified as the |
|
7529 * argument of method. If this request is denied because this Component's |
|
7530 * top-level Window cannot become the focused Window, the request will be |
|
7531 * remembered and will be granted when the Window is later focused by the |
|
7532 * user. |
|
7533 * <p> |
|
7534 * This method cannot be used to set the focus owner to no Component at |
|
7535 * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()} |
|
7536 * instead. |
|
7537 * <p> |
|
7538 * Because the focus behavior of this method is platform-dependent, |
|
7539 * developers are strongly encouraged to use |
|
7540 * {@code requestFocusInWindow(FocusEvent.Cause)} when possible. |
|
7541 * |
|
7542 * <p>Note: Not all focus transfers result from invoking this method. As |
|
7543 * such, a component may receive focus without this or any of the other |
|
7544 * {@code requestFocus} methods of {@code Component} being invoked. |
|
7545 * |
|
7546 * @param cause the cause why the focus is requested |
|
7547 * @see FocusEvent |
|
7548 * @see FocusEvent.Cause |
|
7549 * @see #requestFocusInWindow(FocusEvent.Cause) |
|
7550 * @see java.awt.event.FocusEvent |
|
7551 * @see #addFocusListener |
|
7552 * @see #isFocusable |
|
7553 * @see #isDisplayable |
|
7554 * @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7555 * @since 9 |
|
7556 */ |
|
7557 public void requestFocus(FocusEvent.Cause cause) { |
|
7558 requestFocusHelper(false, true, cause); |
7516 } |
7559 } |
7517 |
7560 |
7518 /** |
7561 /** |
7519 * Requests that this {@code Component} get the input focus, |
7562 * Requests that this {@code Component} get the input focus, |
7520 * and that this {@code Component}'s top-level ancestor |
7563 * and that this {@code Component}'s top-level ancestor |
7576 */ |
7619 */ |
7577 protected boolean requestFocus(boolean temporary) { |
7620 protected boolean requestFocus(boolean temporary) { |
7578 return requestFocusHelper(temporary, true); |
7621 return requestFocusHelper(temporary, true); |
7579 } |
7622 } |
7580 |
7623 |
7581 boolean requestFocus(boolean temporary, FocusEvent.Cause cause) { |
7624 /** |
|
7625 * Requests by the reason of {@code cause} that this {@code Component} get |
|
7626 * the input focus, and that this {@code Component}'s top-level ancestor |
|
7627 * become the focused {@code Window}. This component must be |
|
7628 * displayable, focusable, visible and all of its ancestors (with |
|
7629 * the exception of the top-level Window) must be visible for the |
|
7630 * request to be granted. Every effort will be made to honor the |
|
7631 * request; however, in some cases it may be impossible to do |
|
7632 * so. Developers must never assume that this component is the |
|
7633 * focus owner until this component receives a FOCUS_GAINED |
|
7634 * event. If this request is denied because this component's |
|
7635 * top-level window cannot become the focused window, the request |
|
7636 * will be remembered and will be granted when the window is later |
|
7637 * focused by the user. |
|
7638 * <p> |
|
7639 * This method returns a boolean value. If {@code false} is returned, |
|
7640 * the request is <b>guaranteed to fail</b>. If {@code true} is |
|
7641 * returned, the request will succeed <b>unless</b> it is vetoed, or an |
|
7642 * extraordinary event, such as disposal of the component's peer, occurs |
|
7643 * before the request can be granted by the native windowing system. Again, |
|
7644 * while a return value of {@code true} indicates that the request is |
|
7645 * likely to succeed, developers must never assume that this component is |
|
7646 * the focus owner until this component receives a FOCUS_GAINED event. |
|
7647 * <p> |
|
7648 * The focus request effect may also depend on the provided |
|
7649 * cause value. If this request is succeed the {FocusEvent} |
|
7650 * generated in the result will receive the cause value specified as the |
|
7651 * argument of the method. |
|
7652 * <p> |
|
7653 * This method cannot be used to set the focus owner to no component at |
|
7654 * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner} |
|
7655 * instead. |
|
7656 * <p> |
|
7657 * Because the focus behavior of this method is platform-dependent, |
|
7658 * developers are strongly encouraged to use |
|
7659 * {@code requestFocusInWindow} when possible. |
|
7660 * <p> |
|
7661 * Every effort will be made to ensure that {@code FocusEvent}s |
|
7662 * generated as a |
|
7663 * result of this request will have the specified temporary value. However, |
|
7664 * because specifying an arbitrary temporary state may not be implementable |
|
7665 * on all native windowing systems, correct behavior for this method can be |
|
7666 * guaranteed only for lightweight {@code Component}s. |
|
7667 * This method is not intended |
|
7668 * for general use, but exists instead as a hook for lightweight component |
|
7669 * libraries, such as Swing. |
|
7670 * <p> |
|
7671 * Note: Not all focus transfers result from invoking this method. As |
|
7672 * such, a component may receive focus without this or any of the other |
|
7673 * {@code requestFocus} methods of {@code Component} being invoked. |
|
7674 * |
|
7675 * @param temporary true if the focus change is temporary, |
|
7676 * such as when the window loses the focus; for |
|
7677 * more information on temporary focus changes see the |
|
7678 *<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
7679 * |
|
7680 * @param cause the cause why the focus is requested |
|
7681 * @return {@code false} if the focus change request is guaranteed to |
|
7682 * fail; {@code true} if it is likely to succeed |
|
7683 * @see FocusEvent |
|
7684 * @see FocusEvent.Cause |
|
7685 * @see #addFocusListener |
|
7686 * @see #isFocusable |
|
7687 * @see #isDisplayable |
|
7688 * @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7689 * @since 9 |
|
7690 */ |
|
7691 protected boolean requestFocus(boolean temporary, FocusEvent.Cause cause) { |
7582 return requestFocusHelper(temporary, true, cause); |
7692 return requestFocusHelper(temporary, true, cause); |
7583 } |
7693 } |
|
7694 |
7584 /** |
7695 /** |
7585 * Requests that this Component get the input focus, if this |
7696 * Requests that this Component get the input focus, if this |
7586 * Component's top-level ancestor is already the focused |
7697 * Component's top-level ancestor is already the focused |
7587 * Window. This component must be displayable, focusable, visible |
7698 * Window. This component must be displayable, focusable, visible |
7588 * and all of its ancestors (with the exception of the top-level |
7699 * and all of its ancestors (with the exception of the top-level |
7627 */ |
7738 */ |
7628 public boolean requestFocusInWindow() { |
7739 public boolean requestFocusInWindow() { |
7629 return requestFocusHelper(false, false); |
7740 return requestFocusHelper(false, false); |
7630 } |
7741 } |
7631 |
7742 |
7632 boolean requestFocusInWindow(FocusEvent.Cause cause) { |
7743 /** |
|
7744 * Requests by the reason of {@code cause} that this Component get the input |
|
7745 * focus, if this Component's top-level ancestor is already the focused |
|
7746 * Window. This component must be displayable, focusable, visible |
|
7747 * and all of its ancestors (with the exception of the top-level |
|
7748 * Window) must be visible for the request to be granted. Every |
|
7749 * effort will be made to honor the request; however, in some |
|
7750 * cases it may be impossible to do so. Developers must never |
|
7751 * assume that this Component is the focus owner until this |
|
7752 * Component receives a FOCUS_GAINED event. |
|
7753 * <p> |
|
7754 * This method returns a boolean value. If {@code false} is returned, |
|
7755 * the request is <b>guaranteed to fail</b>. If {@code true} is |
|
7756 * returned, the request will succeed <b>unless</b> it is vetoed, or an |
|
7757 * extraordinary event, such as disposal of the Component's peer, occurs |
|
7758 * before the request can be granted by the native windowing system. Again, |
|
7759 * while a return value of {@code true} indicates that the request is |
|
7760 * likely to succeed, developers must never assume that this Component is |
|
7761 * the focus owner until this Component receives a FOCUS_GAINED event. |
|
7762 * <p> |
|
7763 * The focus request effect may also depend on the provided |
|
7764 * cause value. If this request is succeed the {@code FocusEvent} |
|
7765 * generated in the result will receive the cause value specified as the |
|
7766 * argument of the method. |
|
7767 * <p> |
|
7768 * This method cannot be used to set the focus owner to no Component at |
|
7769 * all. Use {@code KeyboardFocusManager.clearGlobalFocusOwner()} |
|
7770 * instead. |
|
7771 * <p> |
|
7772 * The focus behavior of this method can be implemented uniformly across |
|
7773 * platforms, and thus developers are strongly encouraged to use this |
|
7774 * method over {@code requestFocus(FocusEvent.Cause)} when possible. |
|
7775 * Code which relies on {@code requestFocus(FocusEvent.Cause)} may exhibit |
|
7776 * different focus behavior on different platforms. |
|
7777 * |
|
7778 * <p>Note: Not all focus transfers result from invoking this method. As |
|
7779 * such, a component may receive focus without this or any of the other |
|
7780 * {@code requestFocus} methods of {@code Component} being invoked. |
|
7781 * |
|
7782 * @param cause the cause why the focus is requested |
|
7783 * @return {@code false} if the focus change request is guaranteed to |
|
7784 * fail; {@code true} if it is likely to succeed |
|
7785 * @see #requestFocus(FocusEvent.Cause) |
|
7786 * @see FocusEvent |
|
7787 * @see FocusEvent.Cause |
|
7788 * @see java.awt.event.FocusEvent |
|
7789 * @see #addFocusListener |
|
7790 * @see #isFocusable |
|
7791 * @see #isDisplayable |
|
7792 * @see KeyboardFocusManager#clearGlobalFocusOwner |
|
7793 * @since 9 |
|
7794 */ |
|
7795 public boolean requestFocusInWindow(FocusEvent.Cause cause) { |
7633 return requestFocusHelper(false, false, cause); |
7796 return requestFocusHelper(false, false, cause); |
7634 } |
7797 } |
7635 |
7798 |
7636 /** |
7799 /** |
7637 * Requests that this {@code Component} get the input focus, |
7800 * Requests that this {@code Component} get the input focus, |