Java JButton Create createRadioButton(String text, int mnemonic, ActionListener listener, boolean selected)

Here you can find the source of createRadioButton(String text, int mnemonic, ActionListener listener, boolean selected)

Description

create Radio Button

License

Open Source License

Declaration

public static JRadioButton createRadioButton(String text, int mnemonic,
            ActionListener listener, boolean selected) 

Method Source Code

//package com.java2s;
/*//from   w w  w .j a  va 2 s  .  c  o  m
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

import java.awt.*;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Main {
    public static Dimension labelPrefSize = new Dimension(100, 20);

    public static JRadioButton createRadioButton(String text, int mnemonic,
            ActionListener listener, boolean selected) {
        JRadioButton button = new JRadioButton(text);
        button.setMnemonic(mnemonic);
        button.setSelected(selected);
        button.setMinimumSize(labelPrefSize);
        if (listener != null)
            button.addActionListener(listener);
        if (text.length() == 0)
            button.setPreferredSize(labelPrefSize);
        return button;
    }

    public static JRadioButton createRadioButton(String text, int mnemonic,
            boolean selected) {
        return createRadioButton(text, mnemonic, null, selected);
    }

    public static JRadioButton createRadioButton(String text, int mnemonic,
            ActionListener listener) {
        return createRadioButton(text, mnemonic, listener, false);
    }

    public static JRadioButton createRadioButton(String text, int mnemonic) {
        return createRadioButton(text, mnemonic, null, false);
    }

    public static JRadioButton createRadioButton(String text) {
        return createRadioButton(text, -1, null, false);
    }
}

Related

  1. createOkCancelPanel(final JButton okBtn, final JButton cancelBtn)
  2. CreateOptionButtonGroup(Box boxGeneric, Border bdrButtonGroup, String[] elements, String[] commandActions, Dimension elementDimension)
  3. createRadioButton(JComponent parent, String text)
  4. createRadioButton(String name, String command, boolean isSelected, ActionListener listener)
  5. createRadioButton(String text, ButtonGroup buttonGroup, ActionListener... listeners)
  6. createRadioButtonGrouping(String elements[], String title)
  7. createScreenCaptureButton()
  8. createSimpleTextButton(String caption, Action action)
  9. createSmallButton()