Java JButton Create CreateOptionButtonGroup(Box boxGeneric, Border bdrButtonGroup, String[] elements, String[] commandActions, Dimension elementDimension)

Here you can find the source of CreateOptionButtonGroup(Box boxGeneric, Border bdrButtonGroup, String[] elements, String[] commandActions, Dimension elementDimension)

Description

Create Option Button Group

License

Open Source License

Declaration

public static void CreateOptionButtonGroup(Box boxGeneric,
            Border bdrButtonGroup, String[] elements,
            String[] commandActions, Dimension elementDimension) 

Method Source Code

//package com.java2s;
/*//w ww. j  a v  a2  s  . co m
 Part of the Papilio Loader

 Copyright (c) 2010-11 GadgetFactory LLC

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License version 2
 as published by the Free Software Foundation.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software Foundation,
 Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.ButtonGroup;

import javax.swing.JRadioButton;

import javax.swing.border.Border;

public class Main {
    public static void CreateOptionButtonGroup(Box boxGeneric,
            Border bdrButtonGroup, String[] elements,
            String[] commandActions, Dimension elementDimension) {
        ButtonGroup group = new ButtonGroup();
        JRadioButton optElement;
        int i = 0;

        boxGeneric.setBorder(bdrButtonGroup);

        for (String iterElement : elements) {
            optElement = new JRadioButton(iterElement);
            optElement.setActionCommand(commandActions[i]);
            if (elementDimension != null) {
                optElement.setPreferredSize(elementDimension);
                optElement.setMaximumSize(elementDimension);
            }

            boxGeneric.add(optElement);
            group.add(optElement);
            i++;
        }
    }
}

Related

  1. createJButton(String text, String name, ActionListener a)
  2. createLabelButton(String text)
  3. createListButton(Action action)
  4. createNoURLGraphicalButton(String imageName, String alternateText)
  5. createOkCancelPanel(final JButton okBtn, final JButton cancelBtn)
  6. createRadioButton(JComponent parent, String text)
  7. createRadioButton(String name, String command, boolean isSelected, ActionListener listener)
  8. createRadioButton(String text, ButtonGroup buttonGroup, ActionListener... listeners)
  9. createRadioButton(String text, int mnemonic, ActionListener listener, boolean selected)