Example usage for javax.swing JCheckBoxMenuItem doClick

List of usage examples for javax.swing JCheckBoxMenuItem doClick

Introduction

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

Prototype

public void doClick() 

Source Link

Document

Programmatically perform a "click".

Usage

From source file:ffx.ui.MainMenu.java

private JCheckBoxMenuItem addCBMenuItem(JMenu menu, String icon, String actionCommand, int mnemonic,
        int accelerator, final ActionListener actionListener) {

    final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem();

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