Radio button, ComboBox : CheckBox Button « Swing JFC « Java






Radio button, ComboBox

Radio button, ComboBox
  
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;

public class ARadioCombo {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Radio/Combo Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new GridLayout(0, 1));
    Border border = BorderFactory.createTitledBorder("Radio Buttons");
    panel.setBorder(border);
    ButtonGroup group = new ButtonGroup();
    JRadioButton aRadioButton = new JRadioButton("4 slices");
    panel.add(aRadioButton);
    group.add(aRadioButton);
    aRadioButton = new JRadioButton("8 slices", true);
    panel.add(aRadioButton);
    group.add(aRadioButton);
    aRadioButton = new JRadioButton("12 slices");
    panel.add(aRadioButton);
    group.add(aRadioButton);
    aRadioButton = new JRadioButton("16 slices");
    panel.add(aRadioButton);
    group.add(aRadioButton);
    Container contentPane = frame.getContentPane();
    contentPane.add(panel, BorderLayout.WEST);
    panel = new JPanel(new GridLayout(0, 1));
    border = BorderFactory.createTitledBorder("Check Boxes");
    panel.setBorder(border);
    JCheckBox aCheckBox = new JCheckBox("Anchovies");
    panel.add(aCheckBox);
    aCheckBox = new JCheckBox("Garlic", true);
    panel.add(aCheckBox);
    aCheckBox = new JCheckBox("Onions");
    panel.add(aCheckBox);
    aCheckBox = new JCheckBox("Spinach");
    panel.add(aCheckBox);
    contentPane.add(panel, BorderLayout.EAST);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}

           
         
    
  








Related examples in the same category

1.JCheckBox is a widget that has two states. On and Off.
2.Swing CheckBoxesSwing CheckBoxes
3.CheckBox Demo 2CheckBox Demo 2
4. How to use the check box button How to use the check box button
5.CheckBox MnemonicCheckBox Mnemonic
6.Bad Checkbox UIBad Checkbox UI
7.React to menu action and checkbox menuReact to menu action and checkbox menu
8.Swing CheckBox DemoSwing CheckBox Demo
9.CheckBox Item ListenerCheckBox Item Listener
10.Icon CheckBox DemoIcon CheckBox Demo
11.Flat CheckBoxFlat CheckBox
12.Customizing the Icons in a JCheckBox Component
13.Customize these disabled icons
14.Set pressed icon
15.Display an icon when the cursor is moved over the checkbox. This is called the rollover icon.
16.Adding an Icon to the Label of a JCheckBox Component
17.Getting and Setting the State of a JCheckbox Component
18.Creating a JCheckbox Component
19.Check boxes with item changed event.
20.Get or set the selection state of JCheckBox
21.Customize JCheckBox icons
22.Using CheckBox ActionListener to controll font