Java examples for Swing:JButton
get selected button from ButtonGroup
//package com.java2s; import java.util.Enumeration; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; public class Main { /**//w w w.j a v a 2s . c om * 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; } }