JComponent () { JComponent component = myState.getPreferredFocusedComponent(); JComponent fallback = myToolbar.getComponent(); if (component == null || !component.isFocusable()) return fallback; if (!component.isShowing() && fallback.isShowing()) return fallback; return component; }