get Selection from ButtonGroup - Java Swing

Java examples for Swing:JButton

Description

get Selection from ButtonGroup

Demo Code


//package com.java2s;

import java.util.Enumeration;
import javax.swing.ButtonGroup;

import javax.swing.JRadioButton;

public class Main {
    public static JRadioButton getSelection(ButtonGroup group) {
        for (Enumeration e = group.getElements(); e.hasMoreElements();) {
            JRadioButton b = (JRadioButton) e.nextElement();
            if (b.getModel() == group.getSelection()) {
                return b;
            }/*  w w w. j a  v a 2 s .  c o  m*/
        }
        return null;
    }
}

Related Tutorials