Example usage for javax.swing JRadioButtonMenuItem doClick

List of usage examples for javax.swing JRadioButtonMenuItem doClick

Introduction

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

Prototype

public void doClick() 

Source Link

Document

Programmatically perform a "click".

Usage

From source file:ffx.ui.MainMenu.java

private JRadioButtonMenuItem addBGMI(ButtonGroup buttonGroup, JMenu menu, String icon, String actionCommand,
        int mnemonic, int accelerator, final ActionListener actionListener) {

    final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem();

    Action a = new AbstractAction() {
        @Override/*from w w w .  ja v  a 2 s  . c om*/
        public void actionPerformed(ActionEvent e) {
            /**
             * If the ActionEvent is from a ToolBar button, pass it through
             * the JRadioButtonMenuItem.
             */
            if (e.getSource() != menuItem) {
                menuItem.doClick();
                return;
            }
            actionListener.actionPerformed(e);
        }
    };
    this.configureAction(a, icon, actionCommand, mnemonic, accelerator);
    menuItem.setAction(a);
    buttonGroup.add(menuItem);
    menu.add(menuItem);
    return menuItem;
}

From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java

/**
 * Constucts a JMenu named 'name' with a a RadioButton for each
 * object in 'themeArray'./*from w  w  w  . j av  a  2 s  . com*/
 *
 * @param name the visible name for the Menu.
 * @param themeArray the array of themes to put in the menu.
 */
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault());
    themes = themeArray;

    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem defaultItem = null;

    for (int i = 0; i < themes.length; i++) {
        String themeName;

        try {
            themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", ""));
        } catch (MissingResourceException mre) {
            themeName = themes[i].getName();

            Object[] noResourceArgs = { themes[i].getName(), getLocale() };
            MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource"));
            log.error(form.format(noResourceArgs));
        }

        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName);
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);

        // Theme name without spaces is the key for looking up localized item text.
        item.setName(themes[i].getName().replaceAll(" ", ""));

        if (i == 0) {
            item.setSelected(true);
            defaultItem = item;
        }
    }

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);

    defaultItem.doClick();
}