List of usage examples for javax.swing ButtonGroup setSelected
public void setSelected(ButtonModel m, boolean b)
ButtonModel
. From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java
/** * Creates the button panel./* www . j a v a 2 s. c o m*/ */ private void createButtonPanel() { buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.PAGE_AXIS)); JPanel fieldsPanel = new JPanel(); fieldsPanel.add(new JLabel("Search using ")); fieldsPanel.add(Box.createHorizontalStrut(5)); fieldsPanel.setLayout(new BoxLayout(fieldsPanel, BoxLayout.LINE_AXIS)); // create button group for term selection JRadioButton allRadioButton = new JRadioButton(new AbstractAction("Term") { public void actionPerformed(ActionEvent event) { // set search on term searchConceptId = false; doSearch(); } }); JRadioButton idRadioButton = new JRadioButton(new AbstractAction("ID") { public void actionPerformed(ActionEvent event) { // set search on id searchConceptId = true; doSearch(); } }); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(allRadioButton); buttonGroup.add(idRadioButton); buttonGroup.setSelected(allRadioButton.getModel(), true); // add search field terms to fields panel fieldsPanel.add(allRadioButton); fieldsPanel.add(idRadioButton); fieldsPanel.add(Box.createHorizontalGlue()); // create panel that contains button that toggles display of controlsPane JideButton controlsButton = new JideButton(new AbstractAction() { public void actionPerformed(ActionEvent e) { if (controlsPane.isCollapsed()) { controlsPane.setCollapsed(false); } else { controlsPane.setCollapsed(true); } } }); controlsButton.setIcon(new ImageIcon(SearchPanel.class.getResource("resources/configure.png"))); controlsButton.setToolTipText("Click to display or hide configuration panel"); JPanel panel4 = new JPanel(); panel4.setLayout(new BoxLayout(panel4, BoxLayout.LINE_AXIS)); panel4.add(Box.createHorizontalGlue()); panel4.add(new JLabel("Change search and display preferences ")); panel4.add(controlsButton); // add panels to button panel buttonsPanel.add(fieldsPanel); buttonsPanel.add(panel4); }