Java Swing Focus containerContainsFocus(Container cont)

Here you can find the source of containerContainsFocus(Container cont)

Description

containerContainsFocus, does the specified container contain the current focusOwner?

License

Open Source License

Parameter

Parameter Description
cont the specified container

Return

Is the current focusOwner a descendant of the specified container, or the container itself?

Declaration


public static boolean containerContainsFocus(Container cont) 

Method Source Code

//package com.java2s;
import javax.swing.*;

import java.awt.*;

public class Main {
    /**/* ww  w.  ja  va 2s . c o m*/
     * containerContainsFocus, does the specified container contain the current focusOwner?
     *
     * @param cont the specified container
     * @return Is the current focusOwner a descendant of the specified container, or the container itself?
     */

    public static boolean containerContainsFocus(Container cont) {
        Component focusOwner = KeyboardFocusManager
                .getCurrentKeyboardFocusManager().getFocusOwner();
        Component permFocusOwner = KeyboardFocusManager
                .getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        boolean focusOwned;
        focusOwned = ((focusOwner != null) && SwingUtilities
                .isDescendingFrom(focusOwner, cont));
        if (!focusOwned) {
            focusOwned = ((permFocusOwner != null) && SwingUtilities
                    .isDescendingFrom(permFocusOwner, cont));
        }
        return focusOwned;
    }
}

Related

  1. centreInFocusedWindow(Window window, int xOffset, int yOffset)
  2. checkComponentsFocusable(final Component _rootComponent)
  3. clearAWTFocus(Robot robot)
  4. compositeRequestFocus(Component component)
  5. containerContainsFocus(Container cont)
  6. createWizardFocusAdapter()
  7. focusComponent(Component comp)
  8. focusComponentOrChild(Component c)
  9. focusComponentOrChild(Component c, boolean deepest)