package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.*;

public final class MainPanel extends JPanel {
    private MainPanel() {
        super(new BorderLayout());
        Box box = Box.createVerticalBox();
        box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        box.add(new JTextField("Another focusable component"));
        box.add(Box.createVerticalStrut(5));
        ButtonGroup bg1 = new ButtonGroup();
        box.add(makeButtonGroupPanel("Default", bg1));
        box.add(Box.createVerticalStrut(5));

        ButtonGroup bg2 = new ButtonGroup();
        JPanel buttons = makeButtonGroupPanel("FocusTraversalPolicy", bg2);
        buttons.setFocusTraversalPolicyProvider(true);
        buttons.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
            @Override public Component getDefaultComponent(Container focusCycleRoot) {
                ButtonModel selection = bg2.getSelection();
                for (Component c: focusCycleRoot.getComponents()) {
                    JRadioButton r = (JRadioButton) c;
                    if (r.getModel().equals(selection)) {
                        return r;
                    }
                }
                return super.getDefaultComponent(focusCycleRoot);
            }
        });
        box.add(buttons);
        box.add(Box.createVerticalStrut(5));

        Box b = Box.createHorizontalBox();
        b.add(Box.createHorizontalGlue());
        b.add(new JButton(new AbstractAction("clear selection") {
            @Override public void actionPerformed(ActionEvent e) {
                bg1.clearSelection();
                bg2.clearSelection();
            }
        }));
        box.add(b);

        add(box, BorderLayout.NORTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JPanel makeButtonGroupPanel(String title, ButtonGroup bg) {
        JPanel p = new JPanel();
        for (String s: Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee")) {
            JRadioButton rb = new JRadioButton(s);
            bg.add(rb);
            p.add(rb);
            if ("ccc".equals(s)) {
                rb.setSelected(true);
            }
        }
        p.setBorder(BorderFactory.createTitledBorder(title));
        return p;
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -159,16 +159,48 @@
 Arrays;%0A
+import java.util.stream.Stream;%0A
 import j
@@ -1077,32 +1077,35 @@
 getSelection();%0A
+// 
                 
@@ -1152,24 +1152,27 @@
 onents()) %7B%0A
+// 
             
@@ -1214,16 +1214,19 @@
 ton) c;%0A
+// 
         
@@ -1271,24 +1271,27 @@
 lection)) %7B%0A
+// 
             
@@ -1312,16 +1312,19 @@
 turn r;%0A
+// 
         
@@ -1329,32 +1329,34 @@
               %7D%0A
+//
                 
@@ -1347,34 +1347,38 @@
                 
+ 
 %7D%0A
+// 
                 
@@ -1427,16 +1427,265 @@
 eRoot);%0A
+                return Stream.of(focusCycleRoot.getComponents())%0A                             .filter(c -%3E ((JRadioButton) c).getModel().equals(selection))%0A                             .findFirst().orElse(super.getDefaultComponent(focusCycleRoot));%0A
         

use Stream.filter(...).findFirst() instead of for if return