Example usage for javax.swing JRadioButtonMenuItem JRadioButtonMenuItem

List of usage examples for javax.swing JRadioButtonMenuItem JRadioButtonMenuItem

Introduction

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

Prototype

public JRadioButtonMenuItem(Icon icon, boolean selected) 

Source Link

Document

Creates a radio button menu item with the specified image and selection state, but no text.

Usage

From source file:org.yccheok.jstock.gui.MainFrame.java

public void createCountryMenuItem() {
    java.util.List<Country> countries = new ArrayList<Country>(Arrays.asList(Country.values()));
    // Czech is only for currency exchange purpose.
    countries.remove(Country.Czech);/*w  w w  .  j  a  v a2 s .  c o  m*/

    for (final Country country : countries) {
        // Ugly fix on spelling mistake.
        final JMenuItem mi;
        mi = (JRadioButtonMenuItem) jMenu6
                .add(new JRadioButtonMenuItem(country.toHumanReadableString(), country.getIcon()));

        buttonGroup2.add(mi);
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainFrame.this.changeCountry(country);
            }
        });

        if (jStockOptions.getCountry() == country) {
            ((JRadioButtonMenuItem) mi).setSelected(true);
        }
    }
}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

private void initExperimental() {
    JMenu menu = new JMenu("Experimental");
    menu.add(new JLabel("Experimental features, can have bugs", Icons.LEVEL_WARNING, SwingConstants.LEADING));
    menu.add(new JSeparator());
    boolean storeOnDisk = StringUtils.equalsIgnoreCase(System.getProperty("cacheEvents"), "true");
    JRadioButtonMenuItem radioButtonMemory = new JRadioButtonMenuItem("Memory - faster, more memory required",
            !storeOnDisk);//from w w w  .j  ava 2 s.  c  o m
    radioButtonMemory.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.setProperty("cacheEvents", Boolean.FALSE.toString());
        }
    });
    JRadioButtonMenuItem radioButtonDisk = new JRadioButtonMenuItem(
            "Disk with caching - slower, less memory required", storeOnDisk);
    radioButtonDisk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.setProperty("cacheEvents", Boolean.TRUE.toString());
        }
    });
    final ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(radioButtonDisk);
    buttonGroup.add(radioButtonMemory);
    menu.add(new JSeparator(JSeparator.VERTICAL));
    menu.add(new JLabel("Keep parsed log events store:"));
    menu.add(radioButtonMemory);
    menu.add(radioButtonDisk);
    final JCheckBox soapFormatterRemoveMultirefsCbx = new JCheckBox();
    soapFormatterRemoveMultirefsCbx
            .setSelected(configuration.getBoolean(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS, false));
    AbstractAction enableMultiRefRemoveFeature = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance()
                    .getMessageFormatters().getElement(SoapMessageFormatter.class.getName());
            soapMessageFormatter.setRemoveMultiRefs(soapFormatterRemoveMultirefsCbx.isSelected());
            configuration.setProperty(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS,
                    soapFormatterRemoveMultirefsCbx.isSelected());
        }
    };
    enableMultiRefRemoveFeature.putValue(Action.NAME, "Remove mulitRefs from SOAP messages");
    soapFormatterRemoveMultirefsCbx.setAction(enableMultiRefRemoveFeature);
    enableMultiRefRemoveFeature.actionPerformed(null);
    final JCheckBox soapFormatterRemoveXsiForNilElementsCbx = new JCheckBox();
    soapFormatterRemoveXsiForNilElementsCbx
            .setSelected(configuration.getBoolean(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL, false));
    AbstractAction soapFormatterRemoveXsiFromNilAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance()
                    .getMessageFormatters().getElement(SoapMessageFormatter.class.getName());
            soapMessageFormatter
                    .setRemoveXsiForNilElements(soapFormatterRemoveXsiForNilElementsCbx.isSelected());
            configuration.setProperty(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL,
                    soapFormatterRemoveXsiForNilElementsCbx.isSelected());
        }
    };
    soapFormatterRemoveXsiFromNilAction.putValue(Action.NAME,
            "Remove xsi for for NIL elements from SOAP messages");
    soapFormatterRemoveXsiForNilElementsCbx.setAction(soapFormatterRemoveXsiFromNilAction);
    soapFormatterRemoveXsiFromNilAction.actionPerformed(null);
    menu.add(soapFormatterRemoveMultirefsCbx);
    menu.add(soapFormatterRemoveXsiForNilElementsCbx);
    getJMenuBar().add(menu);
    QueryFilter queryFilter = new QueryFilter();
    allPluginables.getLogFiltersContainer().addElement(queryFilter);
    JButton b = new JButton("Throw exception");
    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (System.currentTimeMillis() % 2 == 0) {
                throw new RuntimeException("Exception swing action!");
            } else {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        throw new RuntimeException("Exception from tread!");
                    }
                }).start();
            }
        }
    });
    menu.add(b);
}