Java ButtonGroup get selected AbstractButton
import java.util.Enumeration; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; public class Main { /**//from ww w . j av a2 s. c o m * get selected button from ButtonGroup * @param bg * @return */ public static AbstractButton getSelectedButton(ButtonGroup bg) { Enumeration<AbstractButton> elements = bg.getElements(); while (elements.hasMoreElements()) { AbstractButton button = elements.nextElement(); if (button.isSelected()) return button; } return null; } }