Example usage for javax.swing JRadioButton JRadioButton

List of usage examples for javax.swing JRadioButton JRadioButton

Introduction

In this page you can find the example usage for javax.swing JRadioButton JRadioButton.

Prototype

public JRadioButton(String text, Icon icon) 

Source Link

Document

Creates a radio button that has the specified text and image, and that is initially unselected.

Usage

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton("Yes?", true);
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);//from   w  w  w .j  a  v  a 2s.c  om

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);

    radioGroup1.isSelected(radMarriedNo.getModel());

    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);
}

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton("Yes?", true);
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);/*  w w  w  .  jav a  2s  . c o  m*/

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);

    Enumeration<AbstractButton> e = radioGroup1.getElements();

    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);
}

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton("Yes?", true);
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);// w  w w  .  j  ava 2 s  . c  om

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);

    radioGroup1.remove(radMarriedNo);

    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);
}

From source file:ClipArea.java

public ClipArea() {
    super();/*from  w  ww  .j a v a  2 s . c o  m*/
    Container contentPane = getContentPane();

    canvas = new MyCanvas();
    contentPane.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));
    clipButton = new JRadioButton("Clip", true);
    clipButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clip = true;
            canvas.clipFurther = false;
            canvas.repaint();
        }
    });
    clipFurButton = new JRadioButton("Clip Further");
    clipFurButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            canvas.clipFurther = true;
            canvas.repaint();
        }
    });
    ButtonGroup group = new ButtonGroup();
    group.add(clipButton);
    group.add(clipFurButton);

    panel.add(clipButton);
    panel.add(clipFurButton);
    contentPane.add(BorderLayout.SOUTH, panel);

    // 4. Add a window listener to close the frame properly.
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    pack();
    setVisible(true);
}

From source file:TArea.java

public void init() {
    Container container = getContentPane();

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));

    resetButton = new JRadioButton("Reset", true);

    addButton = new JRadioButton("Add");
    subtractButton = new JRadioButton("Subtract");
    intersectButton = new JRadioButton("Intersect");
    exclusiveORButton = new JRadioButton("ExclusiveOR");

    ButtonGroup group = new ButtonGroup();
    group.add(resetButton);/*  w  w  w  .j a  v  a  2 s.c o  m*/
    group.add(addButton);
    group.add(subtractButton);
    group.add(intersectButton);
    group.add(exclusiveORButton);
    group.add(resetButton);

    resetButton.addActionListener(this);
    addButton.addActionListener(this);
    subtractButton.addActionListener(this);
    intersectButton.addActionListener(this);
    exclusiveORButton.addActionListener(this);

    panel.add(addButton);
    panel.add(subtractButton);
    panel.add(intersectButton);
    panel.add(exclusiveORButton);

    container.add(panel, BorderLayout.NORTH);
    container.add(resetButton, BorderLayout.SOUTH);

    canvas = new DrawingCanvas();
    container.add(canvas);
}

From source file:Wallpaper.java

private static JPanel createPanel() {
    JPanel p = new JPanel();

    ButtonGroup entreeGroup = new ButtonGroup();
    JRadioButton radioButton;/*from  ww w  .j a  v a  2s . c o  m*/
    p.add(radioButton = new JRadioButton("Beef", true));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Chicken"));
    entreeGroup.add(radioButton);
    p.add(radioButton = new JRadioButton("Vegetable"));
    entreeGroup.add(radioButton);

    p.add(new JCheckBox("Ketchup"));
    p.add(new JCheckBox("Mustard"));
    p.add(new JCheckBox("Pickles"));

    p.add(new JLabel("Special requests:"));
    p.add(new JTextField(20));

    JButton orderButton = new JButton("Place Order");
    p.add(orderButton);

    return p;
}

From source file:RadioButtonTest.java

/**
 * Adds a radio button that sets the font size of the sample text.
 * @param name the string to appear on the button
 * @param size the font size that this button sets
 *//* w w  w  .j  av  a  2  s .com*/
public void addRadioButton(String name, final int size) {
    boolean selected = size == DEFAULT_SIZE;
    JRadioButton button = new JRadioButton(name, selected);
    group.add(button);
    buttonPanel.add(button);

    // this listener sets the label font size

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // size refers to the final parameter of the addRadioButton
            // method
            label.setFont(new Font("Serif", Font.PLAIN, size));
        }
    };

    button.addActionListener(listener);
}

From source file:org.altusmetrum.altosuilib_2.AltosUIEnable.java

public void add_units() {
    /* Imperial units setting */

    /* Add label */
    JRadioButton imperial_units = new JRadioButton("Imperial Units", AltosUIPreferences.imperial_units());
    imperial_units.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JRadioButton item = (JRadioButton) e.getSource();
            boolean enabled = item.isSelected();
            AltosUIPreferences.set_imperial_units(enabled);
        }/*from  www. j  a  v  a 2  s .  co m*/
    });
    imperial_units.setToolTipText("Use Imperial units instead of metric");
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 1000;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = il;
    add(imperial_units, c);
}

From source file:BoxLayoutTest.java

public JRadioButton addRadioButton(JPanel p, ButtonGroup g, String name, boolean selected) {
    JRadioButton button = new JRadioButton(name, selected);
    button.addActionListener(this);
    g.add(button);/*from www  .  j a  v  a  2s  . c o m*/
    p.add(button);
    return button;
}

From source file:org.jfree.chart.demo.CategoryLabelPositionsDemo1.java

public static JPanel createDemoPanel() {
    CategoryDataset categorydataset = createDataset();
    chart = createChart(categorydataset);
    JPanel jpanel = new JPanel(new BorderLayout());
    JPanel jpanel1 = new JPanel(new BorderLayout());
    JPanel jpanel2 = new JPanel();
    invertCheckBox = new JCheckBox("Invert Range Axis?");
    invertCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            categoryplot.getRangeAxis().setInverted(CategoryLabelPositionsDemo1.invertCheckBox.isSelected());
        }//from  w  ww. j a  v  a 2 s .  c o m

    });
    jpanel2.add(invertCheckBox);
    ButtonGroup buttongroup = new ButtonGroup();
    horizontalRadioButton = new JRadioButton("Horizontal", false);
    horizontalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.horizontalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
            }
        }

    });
    buttongroup.add(horizontalRadioButton);
    verticalRadioButton = new JRadioButton("Vertical", true);
    verticalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.verticalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.VERTICAL);
            }
        }

    });
    buttongroup.add(verticalRadioButton);
    jpanel2.add(horizontalRadioButton);
    jpanel2.add(verticalRadioButton);
    jpanel2.setBorder(new TitledBorder("Plot Settings: "));
    JPanel jpanel3 = new JPanel(new BorderLayout());
    slider = new JSlider(0, 90, 45);
    slider.setMajorTickSpacing(10);
    slider.setMinorTickSpacing(5);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            CategoryAxis categoryaxis = categoryplot.getDomainAxis();
            categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(
                    ((double) CategoryLabelPositionsDemo1.slider.getValue() * 3.1415926535897931D) / 180D));
        }

    });
    jpanel3.add(slider);
    jpanel3.setBorder(new TitledBorder("Axis Label Rotation Angle:"));
    jpanel1.add("North", jpanel2);
    jpanel1.add(jpanel3);
    jpanel.add(new ChartPanel(chart));
    jpanel.add("South", jpanel1);
    return jpanel;
}