Example usage for javax.swing JRadioButton setText

List of usage examples for javax.swing JRadioButton setText

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.")
public void setText(String text) 

Source Link

Document

Sets the button's text.

Usage

From source file:components.FrameDemo2.java

protected JComponent createOptionControls() {
    JLabel label1 = new JLabel("Decoration options for subsequently created frames:");
    ButtonGroup bg1 = new ButtonGroup();
    JLabel label2 = new JLabel("Icon options:");
    ButtonGroup bg2 = new ButtonGroup();

    //Create the buttons
    JRadioButton rb1 = new JRadioButton();
    rb1.setText("Look and feel decorated");
    rb1.setActionCommand(LF_DECORATIONS);
    rb1.addActionListener(this);
    rb1.setSelected(true);/*from   ww  w.j  ava  2s  .c o m*/
    bg1.add(rb1);
    //
    JRadioButton rb2 = new JRadioButton();
    rb2.setText("Window system decorated");
    rb2.setActionCommand(WS_DECORATIONS);
    rb2.addActionListener(this);
    bg1.add(rb2);
    //
    JRadioButton rb3 = new JRadioButton();
    rb3.setText("No decorations");
    rb3.setActionCommand(NO_DECORATIONS);
    rb3.addActionListener(this);
    bg1.add(rb3);
    //
    //
    JRadioButton rb4 = new JRadioButton();
    rb4.setText("Default icon");
    rb4.setActionCommand(DEFAULT_ICON);
    rb4.addActionListener(this);
    rb4.setSelected(true);
    bg2.add(rb4);
    //
    JRadioButton rb5 = new JRadioButton();
    rb5.setText("Icon from a JPEG file");
    rb5.setActionCommand(FILE_ICON);
    rb5.addActionListener(this);
    bg2.add(rb5);
    //
    JRadioButton rb6 = new JRadioButton();
    rb6.setText("Painted icon");
    rb6.setActionCommand(PAINT_ICON);
    rb6.addActionListener(this);
    bg2.add(rb6);

    //Add everything to a container.
    Box box = Box.createVerticalBox();
    box.add(label1);
    box.add(Box.createVerticalStrut(5)); //spacer
    box.add(rb1);
    box.add(rb2);
    box.add(rb3);
    //
    box.add(Box.createVerticalStrut(15)); //spacer
    box.add(label2);
    box.add(Box.createVerticalStrut(5)); //spacer
    box.add(rb4);
    box.add(rb5);
    box.add(rb6);

    //Add some breathing room.
    box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    return box;
}

From source file:FrameDemo2.java

protected JComponent createOptionControls() {
    JLabel label1 = new JLabel("Decoration options for subsequently created frames:");
    ButtonGroup bg1 = new ButtonGroup();
    JLabel label2 = new JLabel("Icon options:");
    ButtonGroup bg2 = new ButtonGroup();

    // Create the buttons
    JRadioButton rb1 = new JRadioButton();
    rb1.setText("Look and feel decorated");
    rb1.setActionCommand(LF_DECORATIONS);
    rb1.addActionListener(this);
    rb1.setSelected(true);// ww w.j  a  v  a 2s. co  m
    bg1.add(rb1);
    //
    JRadioButton rb2 = new JRadioButton();
    rb2.setText("Window system decorated");
    rb2.setActionCommand(WS_DECORATIONS);
    rb2.addActionListener(this);
    bg1.add(rb2);
    //
    JRadioButton rb3 = new JRadioButton();
    rb3.setText("No decorations");
    rb3.setActionCommand(NO_DECORATIONS);
    rb3.addActionListener(this);
    bg1.add(rb3);
    //
    //
    JRadioButton rb4 = new JRadioButton();
    rb4.setText("Default icon");
    rb4.setActionCommand(DEFAULT_ICON);
    rb4.addActionListener(this);
    rb4.setSelected(true);
    bg2.add(rb4);
    //
    JRadioButton rb5 = new JRadioButton();
    rb5.setText("Icon from a JPEG file");
    rb5.setActionCommand(FILE_ICON);
    rb5.addActionListener(this);
    bg2.add(rb5);
    //
    JRadioButton rb6 = new JRadioButton();
    rb6.setText("Painted icon");
    rb6.setActionCommand(PAINT_ICON);
    rb6.addActionListener(this);
    bg2.add(rb6);

    // Add everything to a container.
    Box box = Box.createVerticalBox();
    box.add(label1);
    box.add(Box.createVerticalStrut(5)); // spacer
    box.add(rb1);
    box.add(rb2);
    box.add(rb3);
    //
    box.add(Box.createVerticalStrut(15)); // spacer
    box.add(label2);
    box.add(Box.createVerticalStrut(5)); // spacer
    box.add(rb4);
    box.add(rb5);
    box.add(rb6);

    // Add some breathing room.
    box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    return box;
}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private JPanel createXPathVersionPanel() {
    JPanel p = new JPanel();
    p.add(new JLabel("XPath Version:"));
    for (Entry<String, String> values : XPathRule.VERSION_DESCRIPTOR.mappings().entrySet()) {
        JRadioButton b = new JRadioButton();
        b.setText(values.getKey());
        b.setActionCommand(b.getText());
        if (values.getKey().equals(XPathRule.VERSION_DESCRIPTOR.defaultValue())) {
            b.setSelected(true);// www  .  ja  v  a  2  s .c o m
        }
        xpathVersionButtonGroup.add(b);
        p.add(b);
    }
    return p;
}

From source file:org.jets3t.gui.UserInputFields.java

/**
 * Builds a user input panel matching the fields specified in the uploader.properties file.
 *
 * @param fieldsPanel//from  ww w.  j av  a  2 s  .c o  m
 * the panel component to add prompt and user input components to.
 * @param uploaderProperties
 * properties specific to the Uploader application that includes the field.* settings
 * necessary to build the User Inputs screen.
 *
 * @return
 * true if there is at least one valid user input field, false otherwise.
 */
public boolean buildFieldsPanel(JPanel fieldsPanel, Jets3tProperties uploaderProperties) {
    int fieldIndex = 0;

    for (int fieldNo = 0; fieldNo < 100; fieldNo++) {
        String fieldName = uploaderProperties.getStringProperty("field." + fieldNo + ".name", null);
        String fieldType = uploaderProperties.getStringProperty("field." + fieldNo + ".type", null);
        String fieldPrompt = uploaderProperties.getStringProperty("field." + fieldNo + ".prompt", null);
        String fieldOptions = uploaderProperties.getStringProperty("field." + fieldNo + ".options", null);
        String fieldDefault = uploaderProperties.getStringProperty("field." + fieldNo + ".default", null);

        if (fieldName == null) {
            log.debug("No field with index number " + fieldNo);
            continue;
        } else {
            if (fieldType == null || fieldPrompt == null) {
                log.warn("Field '" + fieldName + "' missing .type or .prompt properties");
                continue;
            }

            if ("message".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
            } else if ("radio".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JPanel optionsPanel = skinsFactory.createSkinnedJPanel("OptionsPanel");
                optionsPanel.setLayout(new GridBagLayout());
                int columnOffset = 0;
                ButtonGroup buttonGroup = new ButtonGroup();
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    JRadioButton radioButton = skinsFactory.createSkinnedJRadioButton(fieldName);
                    radioButton.setText(option);
                    buttonGroup.add(radioButton);

                    if (fieldDefault != null && fieldDefault.equals(option)) {
                        // This option is the default one.
                        radioButton.setSelected(true);
                    } else if (buttonGroup.getButtonCount() == 1) {
                        // Make first button the default.
                        radioButton.setSelected(true);
                    }

                    optionsPanel.add(radioButton, new GridBagConstraints(columnOffset++, 0, 1, 1, 0, 0,
                            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
                }
                fieldsPanel.add(optionsPanel, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.NONE, insetsNone, 0, 0));

                userInputComponentsMap.put(fieldName, buttonGroup);
            } else if ("selection".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JComboBox comboBox = skinsFactory.createSkinnedJComboBox(fieldName);
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    comboBox.addItem(option);
                }

                if (fieldDefault != null) {
                    comboBox.setSelectedItem(fieldDefault);
                }

                fieldsPanel.add(comboBox, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, comboBox);
            } else if ("text".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextField textField = skinsFactory.createSkinnedJTextField(fieldName);
                if (fieldDefault != null) {
                    textField.setText(fieldDefault);
                }

                fieldsPanel.add(textField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textField);
            } else if ("password".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JPasswordField passwordField = skinsFactory.createSkinnedJPasswordField(fieldName);
                if (fieldDefault != null) {
                    passwordField.setText(fieldDefault);
                }

                fieldsPanel.add(passwordField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, passwordField);
            } else if (fieldType.equals("textarea")) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 2, 1, 0, 0,
                        GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextArea textArea = skinsFactory.createSkinnedJTextArea(fieldName);
                textArea.setLineWrap(true);
                if (fieldDefault != null) {
                    textArea.setText(fieldDefault);
                }

                JScrollPane scrollPane = skinsFactory.createSkinnedJScrollPane(fieldName);
                scrollPane.setViewportView(textArea);
                fieldsPanel.add(scrollPane, new GridBagConstraints(0, fieldIndex++, 2, 1, 1, 1,
                        GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textArea);
            } else {
                log.warn("Unrecognised .type setting for field '" + fieldName + "'");
            }
        }
    }

    return isUserInputFieldsAvailable();
}