public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
        HashSet<Component> set = new HashSet<Component>();
        set.add(currentFocusOwner);

        Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
        Component comp = currentFocusOwner;
        while ((rootAncestor != null) &&
                !(rootAncestor.isShowing() &&
                        rootAncestor.isFocusable() &&
                        rootAncestor.isEnabled()))
        {
            comp = rootAncestor;
            rootAncestor = comp.getFocusCycleRootAncestor();
        }
        if (rootAncestor != null) {
            FocusTraversalPolicy policy =
                    rootAncestor.getFocusTraversalPolicy();
            Component toFocus = policy.getComponentAfter(rootAncestor, comp);

            while ((toFocus != null) && (set.contains(toFocus) == false)) {
                set.add(toFocus);
                toFocus = policy.getComponentAfter(rootAncestor, toFocus);
            }

            toFocus = policy.getComponentBefore(rootAncestor, comp);

            while ((toFocus != null) && (set.contains(toFocus) == false)) {
                set.add(toFocus);
                toFocus = policy.getComponentBefore(rootAncestor, toFocus);
            }
        }
        return set;
    }