List of usage examples for java.awt Container setFocusCycleRoot
public void setFocusCycleRoot(boolean focusCycleRoot)
From source file:Main.java
public static Component getNearestFocusableComponent(Component c, Container desiredRoot) { if (c == null) c = desiredRoot;//from ww w.ja v a 2 s . c o m if (c == null) c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); boolean cachedFocusCycleRoot = false; // make the desiredRoot into a focusCycleRoot if (desiredRoot != null) { cachedFocusCycleRoot = desiredRoot.isFocusCycleRoot(); if (!cachedFocusCycleRoot) desiredRoot.setFocusCycleRoot(true); } Container focusRoot = null; if (c instanceof Container) { Container cnt = (Container) c; focusRoot = cnt.isFocusCycleRoot(cnt) ? cnt : cnt.getFocusCycleRootAncestor(); } else focusRoot = c.getFocusCycleRootAncestor(); Component focuser = null; if (focusRoot != null) //zw, remarked - selected component should become focused //focuser = focusRoot.getFocusTraversalPolicy().getLastComponent(focusRoot); focuser = c; //zw, added - selected component should become focused // restore the desiredRoot to its previous state if (desiredRoot != null && !cachedFocusCycleRoot) { desiredRoot.setFocusCycleRoot(cachedFocusCycleRoot); } return focuser; }