List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:DialogSeparator.java
public FlightReservation() { super("Dialog "); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(new DialogSeparator("Options")); ButtonGroup group = new ButtonGroup(); JRadioButton r1 = new JRadioButton("First class"); group.add(r1); c.add(r1);//from w w w . jav a 2s. co m JRadioButton r2 = new JRadioButton("Business"); group.add(r2); c.add(r2); JRadioButton r3 = new JRadioButton("Coach"); group.add(r3); c.add(r3); c.add(new DialogSeparator()); JButton b3 = new JButton("Exit"); c.add(b3); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setSize(300, 200); setVisible(true); }
From source file:Main.java
public Main(String title) { super(title); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container contentPane = this.getContentPane(); ButtonGroup group = new ButtonGroup(); small = new JRadioButton("small"); medium = new JRadioButton("medium"); large = new JRadioButton("large"); group.add(small); group.add(medium);//from w w w . j av a2 s .c o m group.add(large); button = new JButton("Click here."); button.setBounds(100, 50, 100, 50); JPanel center = new JPanel(); center.setLayout(null); center.add(button); contentPane.add(center, BorderLayout.CENTER); JPanel north = new JPanel(); north.add(small); north.add(medium); north.add(large); contentPane.add(north, BorderLayout.NORTH); ChangeSize listener = new ChangeSize(button); small.addItemListener(listener); medium.addItemListener(listener); large.addItemListener(listener); }
From source file:GeMSE.Visualization.BoxAndWhiskerPlot.java
/** * Creates new form BoxAndWhiskerPlot/*from w ww. j a v a2 s .c o m*/ * * @param space */ public BoxAndWhiskerPlot(Space space) { initComponents(); _space = space; ButtonGroup group = new ButtonGroup(); group.add(RowsCategoryRB); group.add(ColumnsCategoryRB); RowsCategoryRB.setSelected(true); Plot(); }
From source file:RadioButtonDemo.java
public RadioButtonDemo() { super(new BorderLayout()); //Create the radio buttons. JRadioButton birdButton = new JRadioButton(birdString); birdButton.setMnemonic(KeyEvent.VK_B); birdButton.setActionCommand(birdString); birdButton.setSelected(true);/*from w ww.ja va 2 s.co m*/ JRadioButton catButton = new JRadioButton(catString); catButton.setMnemonic(KeyEvent.VK_C); catButton.setActionCommand(catString); JRadioButton dogButton = new JRadioButton(dogString); dogButton.setMnemonic(KeyEvent.VK_D); dogButton.setActionCommand(dogString); JRadioButton rabbitButton = new JRadioButton(rabbitString); rabbitButton.setMnemonic(KeyEvent.VK_R); rabbitButton.setActionCommand(rabbitString); JRadioButton pigButton = new JRadioButton(pigString); pigButton.setMnemonic(KeyEvent.VK_P); pigButton.setActionCommand(pigString); //Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(birdButton); group.add(catButton); group.add(dogButton); group.add(rabbitButton); group.add(pigButton); //Register a listener for the radio buttons. birdButton.addActionListener(this); catButton.addActionListener(this); dogButton.addActionListener(this); rabbitButton.addActionListener(this); pigButton.addActionListener(this); //Set up the picture label. picture = new JLabel(createImageIcon("images/" + birdString + ".gif")); //The preferred size is hard-coded to be the width of the //widest image and the height of the tallest image. //A real program would compute this. picture.setPreferredSize(new Dimension(177, 122)); //Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(birdButton); radioPanel.add(catButton); radioPanel.add(dogButton); radioPanel.add(rabbitButton); radioPanel.add(pigButton); add(radioPanel, BorderLayout.LINE_START); add(picture, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:MessageDigestTest.java
public void addCheckBox(Container c, String name, ButtonGroup g, boolean selected, ActionListener listener) { JCheckBox b = new JCheckBox(name, selected); c.add(b);/* ww w . jav a2 s . com*/ g.add(b); b.addActionListener(listener); }
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); p.add(button);/* www . j a v a 2 s . co m*/ return button; }
From source file:com.eviware.soapui.support.editor.inspectors.auth.ExpirationTimeChooser.java
private void initializeRadioButtons() { long serverIssuedExpirationTime = profile.getAccessTokenExpirationTime(); String serverIssuedExpirationTimeLabel; if (serverIssuedExpirationTime > 0) { serverIssuedExpirationTimeLabel = getMostLegibleTimeString(serverIssuedExpirationTime); } else {/*from w ww. j a v a2s . co m*/ serverIssuedExpirationTimeLabel = "No expiration"; } serverExpirationTimeOption = new JRadioButton( "Use expiration time from authorization server: " + serverIssuedExpirationTimeLabel); serverExpirationTimeOption.setName(SERVER_EXPIRATION_RADIO_NAME); ActionListener checkBoxMonitor = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { timeTextField.setEnabled(manualExpirationTimeOption.isSelected()); timeUnitCombo.setEnabled(manualExpirationTimeOption.isSelected()); } }; serverExpirationTimeOption.addActionListener(checkBoxMonitor); manualExpirationTimeOption = new JRadioButton("Custom"); manualExpirationTimeOption.setName(MANUAL_EXPIRATION_RADIO_NAME); manualExpirationTimeOption.addActionListener(checkBoxMonitor); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(serverExpirationTimeOption); buttonGroup.add(manualExpirationTimeOption); if (profile.useManualAccessTokenExpirationTime()) { manualExpirationTimeOption.setSelected(true); } else { serverExpirationTimeOption.setSelected(true); } }
From source file:Main.java
public Main() { JPanel northPanel = new JPanel(); northPanel.setLayout(new GridLayout(3, 1, 0, 5)); northPanel.add(label);/*from w ww.jav a2 s.com*/ northPanel.add(button); northPanel.add(comboBox); add(northPanel, BorderLayout.NORTH); JPanel southPanel = new JPanel(); ItemHandler handler = new ItemHandler(); southPanel.setLayout(new GridLayout(1, radio.length)); ButtonGroup group = new ButtonGroup(); for (int i = 0; i < radio.length; i++) { radio[i] = new JRadioButton(strings[i]); radio[i].addItemListener(handler); group.add(radio[i]); southPanel.add(radio[i]); } add(southPanel, BorderLayout.SOUTH); setSize(300, 200); setVisible(true); radio[0].setSelected(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public Main() { JRadioButton radMarriedYes = new JRadioButton("Yes?"); 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 a v a 2 s. c o m add(radMarriedYes); add(radMarriedNo); add(radGolfYes); add(radGolfNo); radioGroup1.add(radMarriedYes); radioGroup1.add(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: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 a2s . c o m*/ add(radMarriedYes); add(radMarriedNo); add(radGolfYes); add(radGolfNo); radioGroup1.add(radMarriedYes); radioGroup1.add(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); }