Java 类javax.swing.JRadioButton 实例源码

项目:jdk8u-jdk    文件:LWCheckboxPeer.java   
CheckboxDelegate() {
    super();
    cb = new JCheckBox() {
        @Override
        public boolean hasFocus() {
            return getTarget().hasFocus();
        }
    };
    rb = new JRadioButton() {
        @Override
        public boolean hasFocus() {
            return getTarget().hasFocus();
        }
    };
    setLayout(null);
    setRadioButton(false);
    add(rb);
    add(cb);
}
项目:incubator-netbeans    文件:RevertModifications.java   
MoreCommitsRevertType (RepositoryFile repositoryFile, JRadioButton button) {
    super(button);
    startPath =
        new RepositoryPaths(
            repositoryFile,
            null,
            null,
            getPanel().startRevisionTextField,
            getPanel().startSearchButton
        );
    startPath.addPropertyChangeListener(RevertModifications.this);
    startPath.setupBehavior(null, 0, null, SvnSearch.SEACRH_HELP_ID_REVERT);

    endPath =
        new RepositoryPaths(
            repositoryFile,
            null,
            null,
            getPanel().endRevisionTextField,
            getPanel().endSearchButton
        );
    endPath.addPropertyChangeListener(RevertModifications.this);
    endPath.setupBehavior(null, 0, null, SvnSearch.SEACRH_HELP_ID_REVERT);
}
项目:Equella    文件:DRMRightsTab.java   
public SectorPanel()
{
    super(CurrentLocale.get("com.dytech.edge.admin.wizard.editor.drm.drmrightstab.restrictwarning"), false); //$NON-NLS-1$

    restrict = new JRadioButton(
        CurrentLocale.get("com.dytech.edge.admin.wizard.editor.drm.drmrightstab.restrictedu"), true); //$NON-NLS-1$
    selectable = new JRadioButton(
        CurrentLocale.get("com.dytech.edge.admin.wizard.editor.drm.drmrightstab.contributor")); //$NON-NLS-1$

    ButtonGroup group = new ButtonGroup();
    group.add(restrict);
    group.add(selectable);

    final int height = restrict.getPreferredSize().height;
    final int[] rows = {height, height};
    final int[] cols = {TableLayout.FILL};

    setInnerLayout(new TableLayout(rows, cols, 5, 5));
    addInner(restrict, new Rectangle(0, 0, 1, 1));
    addInner(selectable, new Rectangle(0, 1, 1, 1));

    setSelected(false);
}
项目:incubator-netbeans    文件:AddServerInstanceWizard.java   
static JRadioButton[] listAvailableProviders(String path) {
    List<JRadioButton> res = new ArrayList<JRadioButton>();

    for (Action a : Utilities.actionsForPath(path+"/Actions")) { // NOI18N
        if (a == null) {
            continue;
        }
        Object msg = a.getValue("wizardMessage"); // NOI18N
        if (msg instanceof String) {
            JRadioButton button = new JRadioButton((String)msg);
            button.putClientProperty("action", a); // NOI18N
            res.add(button);
        }
    }

    return res.toArray(new JRadioButton[0]);
}
项目:openjdk-jdk10    文件:LWCheckboxPeer.java   
CheckboxDelegate() {
    super();
    cb = new JCheckBox() {
        @Override
        public boolean hasFocus() {
            return getTarget().hasFocus();
        }
    };
    rb = new JRadioButton() {
        @Override
        public boolean hasFocus() {
            return getTarget().hasFocus();
        }
    };
    setLayout(null);
    setRadioButton(false);
    add(rb);
    add(cb);
}
项目:ramus    文件:SectorNameEditor.java   
private Component getReplacemetPanel() {
    JPanel group = new JPanel(new GridLayout(0, 1));
    group.setBorder(BorderFactory.createTitledBorder(ResourceLoader
            .getString("ArrowReplacementType.name")));
    group.add(safe = new JRadioButton("ArrowReplacementType.safe"));
    group.add(children = new JRadioButton("ArrowReplacementType.branching"));
    group.add(all = new JRadioButton("ArrowReplacementType.everywhere"));
    safe.setSelected(true);

    ButtonGroup g = new ButtonGroup();
    g.add(children);
    g.add(all);
    g.add(safe);

    setReplaceEnable(false);

    return group;
}
项目:incubator-netbeans    文件:ExtractInlinedStylePanel.java   
private void setSectionMode(Mode mode) {
    this.selection = mode;
    JRadioButton select;
    switch (selection) {
        case refactorToExistingEmbeddedSection:
            //select first existing css section if available
            if(existingEmbeddedSectionsComboBox.getModel().getSize() > 1) { //first item is the 'create new section'
                existingEmbeddedSectionsComboBox.setSelectedIndex(1); //select second item, which is the first existing section
            }
        case refactorToNewEmbeddedSection:
            select = embeddedSectionRB;
            break;
        case refactorToExistingExternalSheet:
        case refactorToReferedExternalSheet:
        case refactorToNewExternalSheet:
            select = externalSheetRB;
            break;
        default:
            throw new IllegalStateException();
    }
    select.setSelected(true);


}
项目:Equella    文件:AbstractChoiceDialog.java   
public void addChoice(final String key, String displayText)
{
    final JRadioButton rb = new JRadioButton(displayText);
    if( doubleClickToSelect )
    {
        rb.addMouseListener(new MouseAdapter()
        {
            @Override
            public void mouseClicked(MouseEvent e)
            {
                if( e.getClickCount() >= 2 )
                {
                    addClicked(key);
                }
            }
        });
    }

    choices.addButton(rb, key);

    // Add after the instructions label and any existing choices
    add(rb, choices.size());
}
项目:rapidminer    文件:NewRepositoryDialog.java   
@Override
protected void finish() {
    try {
        if (localButton.isSelected()) {
            localRepositoryPanel.makeRepository();
        } else {
            // check all custom repository radio buttons
            for (Pair<RepositoryConfigurationPanel, JRadioButton> value : repoConfigPanels.values()) {

                // once we have found the selected radio button
                if (value.getSecond().isSelected()) {

                    // lookup the corresponding factory and create the repository
                    value.getFirst().makeRepository();
                }
            }
        }
        super.finish();
    } catch (RepositoryException e) {
        SwingTools.showSimpleErrorMessage("cannot_create_repository", e);
    }
}
项目:jiracli    文件:CredentialsPanel.java   
private CredentialsPanel(String username, String url) {
    this.url = url;
    this.usernamePassword = new JRadioButton("Username and password");
    this.usernamePassword.addActionListener(new RadioButtonListener());
    this.anonymous = new JRadioButton("Anonymous access");
    this.anonymous.addActionListener(new RadioButtonListener());
    this.buttonGroup = new ButtonGroup();
    this.buttonGroup.add(usernamePassword);
    this.buttonGroup.add(anonymous);
    this.usernameLabel = new JLabel("Username:");
    this.username = new JTextField(Objects.toString(username, ""), 20);
    this.passwordLabel = new JLabel("Password:");
    this.password = new JPasswordField(20);
    if (username == null || username.isEmpty()) {
        this.anonymous.setSelected(true);
    } else {
        this.usernamePassword.setSelected(true);
        this.password.addAncestorListener(new RequestFocusListener());
    }
    radioButtonToggled();
    layoutComponents();
}
项目:marathonv5    文件:DialogDemo.java   
/**
 * Like createPane, but creates a pane with 2 columns of radio buttons. The
 * number of buttons passed in *must* be even.
 */
private JPanel create2ColPane(String description, JRadioButton[] radioButtons, JButton showButton) {
    JLabel label = new JLabel(description);
    int numPerColumn = radioButtons.length / 2;

    JPanel grid = new JPanel(new GridLayout(0, 2));
    for (int i = 0; i < numPerColumn; i++) {
        grid.add(radioButtons[i]);
        grid.add(radioButtons[i + numPerColumn]);
    }

    JPanel box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
    box.add(label);
    grid.setAlignmentX(0.0f);
    box.add(grid);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(box, BorderLayout.PAGE_START);
    pane.add(showButton, BorderLayout.PAGE_END);

    return pane;
}
项目:OrthancAnonymization    文件:AnonActionProfileListener.java   
public AnonActionProfileListener(JComboBox<Object> anonProfiles, JLabel profileLabel, JRadioButton radioBodyCharac1, 
        JRadioButton radioBodyCharac2, JRadioButton radioDates1, JRadioButton radioDates2, JRadioButton radioBd2, 
        JRadioButton radioBd1, JRadioButton radioPt1, JRadioButton radioPt2,
        JRadioButton radioSc1, JRadioButton radioSc2, JRadioButton radioDesc1, JRadioButton radioDesc2){
    this.profileLabel = profileLabel;
    this.anonProfiles = anonProfiles;
    this.radioBodyCharac1 = radioBodyCharac1;
    this.radioBodyCharac2 = radioBodyCharac2;
    this.radioDates1 = radioDates1;
    this.radioDates2 = radioDates2;
    this.radioBd2 = radioBd2;
    this.radioBd1 = radioBd1;
    this.radioPt1 = radioPt1;
    this.radioPt2 = radioPt2;
    this.radioSc1 = radioSc1;
    this.radioSc2 = radioSc2;
    this.radioDesc1 = radioDesc1;
    this.radioDesc2 = radioDesc2;
}
项目:VASSAL-src    文件:WizardSupport.java   
private JRadioButton createTutorialButton(final WizardController controller, final Map settings) {
  JRadioButton b = new JRadioButton(Resources.getString("WizardSupport.LoadTutorial")); //$NON-NLS-1$
  b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      controller.setProblem(Resources.getString("WizardSupport.LoadingTutorial")); //$NON-NLS-1$
      try {
        new TutorialLoader(controller, settings, new BufferedInputStream(tutorial.getTutorialContents()), POST_INITIAL_STEPS_WIZARD, tutorial).start();
      }
      catch (IOException e1) {
        logger.error("", e1);
        controller.setProblem(Resources.getString("WizardSupport.ErrorLoadingTutorial")); //$NON-NLS-1$
      }
    }
  });
  return b;
}
项目:VASSAL-src    文件:WizardSupport.java   
private JRadioButton createLoadSavedGameButton(final WizardController controller, final Map settings) {
  JRadioButton b = new JRadioButton(Resources.getString("WizardSupport.LoadSavedGame")); //$NON-NLS-1$
  b.addActionListener(new ActionListener() {
    @SuppressWarnings("unchecked")
    public void actionPerformed(ActionEvent e) {
      settings.put(WizardSupport.ACTION_KEY, LOAD_GAME_ACTION);
      Wizard wiz = new BranchingWizard(new LoadSavedGamePanels(), POST_LOAD_GAME_WIZARD).createWizard();
      settings.put(POST_INITIAL_STEPS_WIZARD, wiz);
      controller.setForwardNavigationMode(WizardController.MODE_CAN_CONTINUE);
      controller.setProblem(null);
    }
  });
  return b;
}
项目:OpenDA    文件:Query.java   
/** Set the current value in the entry with the given name.
 *  If the entry is not a checkbox, then throw an exception.
 *  Notify listeners that the value has changed.
 *  @exception NoSuchElementException If there is no item with the
 *   specified name.  Note that this is a runtime exception, so it
 *   need not be declared explicitly.
 *  @exception IllegalArgumentException If the entry is not a
 *   checkbox.  This is a runtime exception, so it
 *   need not be declared explicitly.
 */
public void setBoolean(String name, boolean value)
    throws NoSuchElementException, IllegalArgumentException {
    Object result = _entries.get(name);
    if (result == null) {
        throw new NoSuchElementException(
            "No item named \"" + name + "\" in the query box.");
    }
    if (result instanceof JRadioButton) {
        ((JRadioButton) result).setSelected(value);
    } else {
        throw new IllegalArgumentException(
            "Item named \""
                + name
                + "\" is not a radio button, and hence does not have "
                + "a boolean value.");
    }
    _notifyListeners(name);
}
项目:Moenagade    文件:LayoutStyle.java   
private Icon getIcon(AbstractButton button) {
    Icon icon = button.getIcon();
    if (icon != null) {
        return icon;
    }
    String key = null;
    if (button instanceof JCheckBox) {
        key = "CheckBox.icon";
    } else if (button instanceof JRadioButton) {
        key = "RadioButton.icon";
    }
    if (key != null) {
        Object oIcon = UIManager.get(key);
        if (oIcon instanceof Icon) {
            return (Icon)oIcon;
        }
    }
    return null;
}
项目:JuggleMasterPro    文件:PrintIconRadioJButton.java   
public PrintIconRadioJButton(   ControlJFrame objPcontrolJFrame,
                                String strPkey,
                                String strPimage,
                                boolean bolPselected,
                                ButtonGroup objPbuttonGroup,
                                ActionListener objPactionListener) {

    // Create widgets :
    this.objGjLabel =
                        new ExtendedJLabel(objPcontrolJFrame, objPcontrolJFrame .getJuggleMasterPro()
                                                                                .getImageIcon(strPimage, Constants.bytS_UNCLASS_NO_VALUE));
    this.objGjRadioButton = new JRadioButton(Tools.getLocaleString(strPkey));
    this.objGjRadioButton.setFont(objPcontrolJFrame.getFont());
    this.objGjRadioButton.setOpaque(true);
    this.objGjRadioButton.setMnemonic(Tools.getMnemonicChar(strPkey));
    this.objGjRadioButton.addActionListener(objPactionListener);
    this.objGjRadioButton.setSelected(bolPselected);
    objPbuttonGroup.add(this.objGjRadioButton);

    // Add widgets :
    this.setLayout(new FlowLayout(FlowLayout.LEADING));
    this.add(this.objGjLabel);
    this.add(this.objGjRadioButton);
    this.setOpaque(true);
}
项目:nativehtml    文件:SwingHtmlInputElement.java   
public void setAttribute(String name, String value) {
    if (name.equals("type") && !name.equals(getAttribute(name))) {
        String text = getAttribute("value");
        if ("checkbox".equalsIgnoreCase(value)) {
            setComponent(new JCheckBox(text));
        } else if ("submit".equalsIgnoreCase(value)) {
            setComponent(new JButton(text == null ? "submit" : text));
        } else if ("radio".equals(value)) {
            setComponent(new JRadioButton(text));
        }
    }
    if (name.equals("value")) {
        if (component instanceof AbstractButton) {
            ((AbstractButton) component).setText(value);
        } else if (component instanceof JTextField) {
            ((JTextField) component).setText(value);
        }
    }

    super.setAttribute(name, value);
}
项目:Equella    文件:AccessEditor.java   
private JComponent createModePanel()
{
    basic = new JRadioButton(CurrentLocale.get("security.editor.mode.basic"));
    advanced = new JRadioButton(CurrentLocale.get("security.editor.mode.advanced"));
    inherited = new JRadioButton(CurrentLocale.get("security.editor.mode.inherited"));

    basic.addActionListener(this);
    advanced.addActionListener(this);
    inherited.addActionListener(this);

    ButtonGroup radiogroup = new ButtonGroup();
    radiogroup.add(basic);
    radiogroup.add(advanced);
    radiogroup.add(inherited);

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel.add(basic);
    panel.add(advanced);
    panel.add(inherited);

    return panel;
}
项目:scorekeeperfrontend    文件:BaseDialog.java   
protected JRadioButton radio(String name)
{
    JRadioButton rb = new JRadioButton(name);
    rb.setActionCommand(name);
    radios.put(name, rb);
    buttonGroup.add(rb);
    return rb;
}
项目:incubator-netbeans    文件:Reset.java   
ResetType getType () {
    String cmd = null;
    for (JRadioButton btn : new JRadioButton[] { panel.rbHard, panel.rbMixed, panel.rbSoft }) {
        if (btn.isSelected()) {
            cmd = btn.getActionCommand();
            break;
        }
    }
    return ResetType.valueOf(cmd);
}
项目:incubator-netbeans    文件:AvailableProvidersPanel.java   
/** Creates new form AvailableProvidersPanel */
public AvailableProvidersPanel(JRadioButton[] arr) {
    initComponents();

    radioPanel.removeAll();
    for (JRadioButton b : arr) {
        radioGroup.add(b);
        radioPanel.add(b);
    }
    arr[0].setSelected(true);
}
项目:incubator-netbeans    文件:JExtendedRadioButton.java   
private static Icon getDisabledIconSafe(JRadioButton radio) {
    Icon icon = radio.getIcon();

    if (icon == null) {
        return getDefaultIcon();
    }

    Icon disabledIcon = radio.getDisabledIcon();

    return (disabledIcon != null) ? disabledIcon : getIconSafe(radio);
}
项目:brModelo    文件:conversorDrawer.java   
public void Escreve(conversorOpcoes Opcoes) {
    Grp = new javax.swing.ButtonGroup();
    Opcoes.Textos.forEach(s -> {
        JLabel lbl = new JLabel(s);
        lbl.setFont(new Font(lbl.getFont().getName(), Font.BOLD, lbl.getFont().getSize()));
        add(lbl);
    });
    add(new JLabel(" "));
    Opcoes.Questoes.forEach(s -> {
        JRadioButton rd = new JRadioButton(s);
        rd.setOpaque(false);
        int i = listaRD.size();
        Grp.add(rd);
        listaRD.add(rd);
        add(rd);
        if (Opcoes.Disables.indexOf(i) > -1) {
            rd.setEnabled(false);
        }
        if (i == Opcoes.opcDefault) {
            rd.setSelected(true);
        }
    });

    if (Opcoes.Observacoes.size() > 0) {
        add(new JLabel("Observação:"));
    }
    Opcoes.Observacoes.forEach(s -> {
        add(new JLabel(s));
    });
}
项目:incubator-netbeans    文件:JExtendedRadioButton.java   
private static Icon getPressedIconSafe(JRadioButton radio) {
    Icon icon = radio.getIcon();

    if (icon == null) {
        return getDefaultIcon();
    }

    Icon pressedIcon = radio.getPressedIcon();

    if (pressedIcon == null) {
        pressedIcon = radio.getSelectedIcon();
    }

    return (pressedIcon != null) ? pressedIcon : getIconSafe(radio);
}
项目:incubator-netbeans    文件:JExtendedRadioButton.java   
private static Icon getRolloverIconSafe(JRadioButton radio) {
    Icon icon = radio.getIcon();

    if (icon == null) {
        return getDefaultIcon();
    }

    Icon rolloverIcon = radio.getRolloverIcon();

    return (rolloverIcon != null) ? rolloverIcon : getIconSafe(radio);
}
项目:incubator-netbeans    文件:JExtendedRadioButton.java   
private static Icon getRolloverSelectedIconSafe(JRadioButton radio) {
    Icon icon = radio.getIcon();

    if (icon == null) {
        return getDefaultIcon();
    }

    Icon rolloverSelectedIcon = radio.getRolloverSelectedIcon();

    if (rolloverSelectedIcon == null) {
        rolloverSelectedIcon = radio.getSelectedIcon();
    }

    return (rolloverSelectedIcon != null) ? rolloverSelectedIcon : getIconSafe(radio);
}
项目:geomapapp    文件:MCSSave.java   
public void save() {
    JPanel panel = new JPanel( new GridLayout(0,1) );
    JLabel label = new JLabel("Save/Download");
    label.setForeground(Color.black);
    panel.add( label );
    ButtonGroup group = new ButtonGroup();
    JRadioButton jpeg = new JRadioButton("JPEG image");
    group.add(jpeg);
    panel.add( jpeg);
    JRadioButton segy = new JRadioButton("SEGY file");
    group.add(segy);
    panel.add( segy);
    nav = new JRadioButton("CDP Navigation");
    group.add(nav);
    panel.add( nav);
    JRadioButton history = new JRadioButton("processing history");
    group.add(history);
    panel.add( history);
    jpeg.setSelected(true);
    int ok = JOptionPane.showOptionDialog( image.getTopLevelAncestor(),
        panel,
        "cruise "+ image.getCruiseID() +", line "+ image.getID(),
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE,
        null, null, null);
    if( ok== JOptionPane.CANCEL_OPTION) return;
    if( nav.isSelected() ||
        segy.isSelected()  
        || history.isSelected() )saveSegy(history.isSelected());
    else saveJPEG();
}
项目:javafx-3d-surface-chart    文件:YesNoRadioButtonHorPanel.java   
@Override
protected List<JRadioButton> createButtons() {
    List<JRadioButton> buttons = new ArrayList<JRadioButton>();

    optYes = new JRadioButton("Yes");
    optYes.setBounds(0, 0, 60, 20);
    buttons.add(optYes);

    optNo = new JRadioButton("No");
    optNo.setBounds(55, 0, 60, 20);
    buttons.add(optNo);

    return buttons;
}
项目:rapidminer    文件:SelectionDialog.java   
/**
 * Checks, if the specified radio button is selected.
 *
 * @param index
 *            Index of the radio button to examine
 * @return true, if the radio button is selected
 */
public boolean isOptionSelected(int index) {
    if (index >= selectionPanel.getComponents().length) {
        return false;
    }
    JRadioButton radioButton = (JRadioButton) selectionPanel.getComponent(index);
    if (radioButton.isSelected()) {
        return true;
    } else {
        return false;
    }
}
项目:Equella    文件:AbstractChoiceDialog.java   
private void ensureSelection()
{
    JRadioButton cb = choices.getSelectedButton();
    if( cb == null || !cb.isEnabled() )
    {
        choices.selectFirstEnabledButton();
    }
}
项目:jaer    文件:AbstractMultiBitRegisterCP.java   
public void updateGUI() {
    for (int i = 0; i < reg.fieldsNumber(); ++i) {
        // if (reg.fieldNeedsUpdate(i))
        if (controls[i] instanceof JRadioButton) {
            ((JRadioButton) controls[i]).setSelected(reg.getPartialValue(i) != 0);
        }
        else {
            ((JTextField) controls[i]).setText(Integer.toString(reg.getPartialValue(i)));
        }
    }
}
项目:openjdk-jdk10    文件:bug8041561.java   
private static void createAndShowGUI() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBackground(Color.BLUE);
    radioButton = new JRadioButton();
    radioButton.setOpaque(false);
    JPanel panel = new JPanel();
    panel.setBackground(Color.BLUE);
    panel.add(radioButton);
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
}
项目:jaer    文件:SPIConfigBit.java   
@Override
public JRadioButton makeGUIControl() {

    final JRadioButton but = new JRadioButton("<html>" + getName() + ": " + getDescription());
    but.setToolTipText("<html>" + toString() + "<br>Select to set bit, clear to clear bit.");
    but.setSelected(value);
    but.setAlignmentX(Component.LEFT_ALIGNMENT);
    but.addActionListener(new SPIConfigBitAction(this));
    setControl(but);
    addObserver(biasgen);   // This observer is responsible for sending data to hardware
    addObserver(this);      // This observer is responsible for GUI update. It calls the updateControl() method
    return but;
}
项目:VASSAL-src    文件:WizardSupport.java   
private JRadioButton createPlayOnlineButton(final WizardController controller, final Map settings) {
  JRadioButton b = new JRadioButton(Resources.getString("WizardSupport.PlayOnline")); //$NON-NLS-1$
  b.addActionListener(new ActionListener() {
    @SuppressWarnings("unchecked")
    public void actionPerformed(ActionEvent e) {
      settings.put(WizardSupport.ACTION_KEY, PLAY_ONLINE_ACTION);
      controller.setForwardNavigationMode(WizardController.MODE_CAN_FINISH);
      controller.setProblem(null);
    }
  });
  return b;
}
项目:etomica    文件:DeviceButtonGroup.java   
public DeviceButtonGroup(Controller controller, int cols) {
    super(controller);
    buttonGroup = new ButtonGroup();
    buttons = new ArrayList<JRadioButton>();
    buttonActions = new ArrayList<IAction>();
    labelHash = new HashMap<String, Integer>();
    this.cols = cols;

    buttonPanel = new JPanel(new GridBagLayout());
}
项目:enigma-vk    文件:ClassMatchingGui.java   
public JRadioButton newRadio(ActionListener listener, ButtonGroup group) {
    JRadioButton button = new JRadioButton(name(), this == getDefault());
    button.setActionCommand(name());
    button.addActionListener(listener);
    group.add(button);
    return button;
}
项目:OpenDA    文件:Query.java   
/** Create an on-off check box.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param defaultValue The default value (true for on).
 */
public void addCheckBox(String name, String label, boolean defaultValue) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JRadioButton checkbox = new JRadioButton();
    checkbox.setBackground(_background);
    checkbox.setOpaque(false);
    checkbox.setSelected(defaultValue);
    _addPair(name, lbl, checkbox, checkbox);
    // Add the listener last so that there is no notification
    // of the first value.
    checkbox.addItemListener(new QueryItemListener(name));
}
项目:etomica    文件:DeviceButtonGroup.java   
/**
 * Adds a radio button with the given label, which (when selected) performs
 * the given action.
 */
public JRadioButton addButton(String label, final IAction action) {
    int id = buttons.size();
    JRadioButton newButton = new JRadioButton(label);
    buttons.add(newButton);
    buttonGroup.add(newButton);
    labelHash.put(label, id);

    GridBagConstraints gbc1 = new GridBagConstraints();
    gbc1.gridx = id % cols;  gbc1.gridy = id/cols;
    gbc1.gridwidth = 1;
    buttonPanel.add(newButton, gbc1);
    if (action != null) {
        ActionListener buttonAction = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    doAction(action);
                }
                catch (RuntimeException e) {
                    System.err.println(e+" "+e.getMessage());
                }
            }
        };
        newButton.addActionListener(buttonAction);
        while (id > buttonActions.size()+1) {
            buttonActions.add(null);
        }
        buttonActions.add(action);
    }
    return newButton;
}
项目:Moenagade    文件:LayoutStyle.java   
/**
 * Returns the amount to indent the specified component if it's
 * a JCheckBox or JRadioButton.  If the component is not a JCheckBox or
 * JRadioButton, 0 will be returned.
 */
int getButtonChildIndent(JComponent c, int position) {
    if ((c instanceof JRadioButton) || (c instanceof JCheckBox)) {
        AbstractButton button = (AbstractButton)c;
        Insets insets = c.getInsets();
        Icon icon = getIcon(button);
        int gap = button.getIconTextGap();
        if (isLeftAligned(button, position)) {
            return insets.left + icon.getIconWidth() + gap;
        } else if (isRightAligned(button, position)) {
            return insets.right + icon.getIconWidth() + gap;
        }
    }
    return 0;
}