Example usage for java.awt FocusTraversalPolicy getComponentBefore

List of usage examples for java.awt FocusTraversalPolicy getComponentBefore

Introduction

In this page you can find the example usage for java.awt FocusTraversalPolicy getComponentBefore.

Prototype

public abstract Component getComponentBefore(Container aContainer, Component aComponent);

Source Link

Document

Returns the Component that should receive the focus before aComponent.

Usage

From source file:Main.java

public static Component findPrevFocus() {
    Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    Container root = c.getFocusCycleRootAncestor();

    FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
    Component prevFocus = policy.getComponentBefore(root, c);
    if (prevFocus == null) {
        prevFocus = policy.getDefaultComponent(root);
    }//from w  w w  .  jav a  2 s.co m
    return prevFocus;
}