Java Swing Focus isParentWindowFocused(Component component)

Here you can find the source of isParentWindowFocused(Component component)

Description

true if the given Component 's has a parent Window (i.e.

License

Open Source License

Parameter

Parameter Description
component the Component to check the parent Window 's focus for.

Return

true if the given Component 's parent Window is currently active.

Declaration

public static boolean isParentWindowFocused(Component component) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

import javax.swing.SwingUtilities;

public class Main {
    /**/*from   w ww.  j ava 2 s  .  c om*/
     * {@code true} if the given {@link Component}'s has a parent {@link Window}
     * (i.e. it's not null) and that {@link Window} is currently active
     * (focused).
     *
     * @param component
     * the {@code Component} to check the parent {@code Window}'s
     * focus for.
     * @return {@code true} if the given {@code Component}'s parent
     * {@code Window} is currently active.
     */
    public static boolean isParentWindowFocused(Component component) {
        final Window window = SwingUtilities.getWindowAncestor(component);
        return window != null && window.isFocused();
    }
}

Related

  1. isFocusable(Component component)
  2. isFocused(Component component)
  3. isFocused(Component component, boolean recoursive)
  4. isParentWindowFocused(Component component)
  5. isParentWindowFocused(Component component)
  6. paintFocusRect(Graphics g, Rectangle r)
  7. postponeFocus(final Component target)
  8. removeFocus(JComponent component)
  9. requestComponentFocus(final Window win, final JComponent comp)