Here you can find the source of setRadioButtonSelected(Window window, String buttonText)
static boolean setRadioButtonSelected(Window window, String buttonText)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.awt.Component; import java.awt.Container; import java.awt.Window; import javax.swing.JRadioButton; public class Main { static boolean setRadioButtonSelected(Window window, String buttonText) { final JRadioButton rb = findRadioButton(window, buttonText); if (rb == null) return false; if (rb.isSelected()) return true; rb.doClick();/* w w w . j a v a 2 s . c om*/ return true; } /** * Traverse a container hierarchy and returns the button with * the given text * */ static JRadioButton findRadioButton(Container container, String text) { Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof JRadioButton) { JRadioButton button = (JRadioButton) component; if (button.getText().equals(text)) { return button; } } else if (component instanceof Container) { JRadioButton button = findRadioButton((Container) component, text); if (button != null) { return button; } } } return null; } }