コード例 #1
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Returns whether the given component is "actively" shown in screen, that is, it or any of its
   * ancestors is focused.
   *
   * @param aComponent the component to determine whether it is actively shown on screen, may be
   *     <code>null</code>.
   * @return <code>true</code> if the given component is actively shown, <code>false</code>
   *     otherwise.
   */
  public static final boolean isActivelyShown(final Component aComponent) {
    final KeyboardFocusManager kbdFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    final Window owner = kbdFocusManager.getFocusedWindow();

    return ((aComponent != null)
        && (owner != null)
        && ((owner == aComponent) || owner.isAncestorOf(aComponent)));
  }
コード例 #2
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
 /**
  * Tries to find the current focused window.
  *
  * @return the current focused window, or <code>null</code> if no such window could be found.
  */
 public static final Window getCurrentWindow() {
   Window owner;
   final KeyboardFocusManager kbdFocusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
   owner = kbdFocusManager.getFocusedWindow();
   if (owner == null) {
     owner = kbdFocusManager.getActiveWindow();
   }
   return owner;
 }