Example usage for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem

List of usage examples for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem

Introduction

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

Prototype

public JCheckBoxMenuItem() 

Source Link

Document

Creates an initially unselected check box menu item with no set text or icon.

Usage

From source file:CheckBoxSample.java

public static void main(String args[]) {

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            String newLabel;//from  www  .j  a v a2s.c  o  m
            Icon newIcon;
            if (selected) {
                newLabel = "Girl";
                newIcon = girlIcon;
            } else {
                newLabel = "Boy";
                newIcon = boyIcon;
            }
            aButton.setText(newLabel);
            aButton.setIcon(newIcon);
        }
    };

    ItemListener iListener = new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            int state = event.getStateChange();
            String newLabel;
            Icon newIcon;
            if (state == ItemEvent.SELECTED) {
                newLabel = "Girl";
                newIcon = girlIcon;
            } else {
                newLabel = "Boy";
                newIcon = boyIcon;
            }
            aButton.setText(newLabel);
            aButton.setIcon(newIcon);
        }
    };

    JFrame frame = new JFrame("CheckBox Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menu.setMnemonic(KeyEvent.VK_M);
    JCheckBoxMenuItem one = new JCheckBoxMenuItem();
    menu.add(one);
    JCheckBoxMenuItem two = new JCheckBoxMenuItem("Boy");
    menu.add(two);
    JCheckBoxMenuItem three = new JCheckBoxMenuItem(boyIcon);
    menu.add(three);
    JCheckBoxMenuItem four = new JCheckBoxMenuItem("Girl", true);
    menu.add(four);
    JCheckBoxMenuItem five = new JCheckBoxMenuItem("Boy", boyIcon);
    five.addItemListener(iListener);
    menu.add(five);
    Icon stateIcon = new DiamondAbstractButtonStateIcon(Color.black);

    UIManager.put("CheckBoxMenuItem.checkIcon", stateIcon);
    JCheckBoxMenuItem six = new JCheckBoxMenuItem("Girl", girlIcon, true);
    six.addActionListener(aListener);
    menu.add(six);

    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionMappingTask.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;//  w ww. java2s .  co  m
    //        item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.SHOW_HIDE_INFO_CONNECTION));
    //        item.setActionCommand(SHOW);
    //        item.addActionListener(this);
    //        menu.add(item);

    itemConfidence = new JMenuItem();
    menu.add(itemConfidence);

    itemImplied = new JCheckBoxMenuItem();
    menu.add(itemImplied);

    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION));
    item.setActionCommand(DELETE);
    item.addActionListener(this);
    menu.add(item);
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

private void buildWindowMenu(JMenu mnuWindow) {
    mnuWindow.removeAll();//w  ww  .j a v  a  2  s  .  c  o m

    JMenuItem mnuItCascade = new JMenuItem();
    mnuItCascade.setAction(_actionMap.get("cascadeFrames"));
    mnuWindow.add(mnuItCascade);

    JMenuItem mnuItTile = new JMenuItem();
    mnuItTile.setAction(_actionMap.get("tileFrames"));
    mnuWindow.add(mnuItTile);

    JMenuItem mnuItTileHorz = new JMenuItem();
    mnuItTileHorz.setAction(_actionMap.get("tileFramesHorizontally"));
    mnuWindow.add(mnuItTileHorz);

    JMenuItem mnuItArrangeIcons = new JMenuItem();
    mnuItArrangeIcons.setAction(_actionMap.get("arrangeIcons"));
    mnuWindow.add(mnuItArrangeIcons);

    JMenuItem mnuItCloseAll = new JMenuItem();
    mnuItCloseAll.setAction(_actionMap.get("closeAllFrames"));
    mnuWindow.add(mnuItCloseAll);

    mnuWindow.addSeparator();

    JMenuItem mnuItChooseFont = new JMenuItem();
    mnuItChooseFont.setAction(_actionMap.get("chooseFont"));
    mnuWindow.add(mnuItChooseFont);

    mnuWindow.addSeparator();

    JMenu mnuLF = new JMenu();
    mnuLF.setName("mnuLF");
    mnuLF.setText(_resourceMap.getString("mnuLF.text"));
    mnuWindow.add(mnuLF);

    JMenuItem mnuItMetalLF = new JMenuItem();
    mnuItMetalLF.setAction(_actionMap.get("metalLookAndFeel"));
    mnuLF.add(mnuItMetalLF);

    JMenuItem mnuItWindowsLF = new JMenuItem();
    mnuItWindowsLF.setAction(_actionMap.get("systemLookAndFeel"));
    mnuLF.add(mnuItWindowsLF);

    try {
        // Nimbus L&F was added in update java 6 update 10.
        Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel").newInstance();
        JMenuItem mnuItNimbusLF = new JMenuItem();
        mnuItNimbusLF.setAction(_actionMap.get("nimbusLookAndFeel"));
        mnuLF.add(mnuItNimbusLF);
    } catch (Exception e) {
        // The Nimbus L&F is not available, no matter.
    }
    mnuWindow.addSeparator();

    int i = 1;
    for (final JInternalFrame frame : _frames) {
        JMenuItem windowItem = new JCheckBoxMenuItem();
        if (i < 10) {
            windowItem.setText(String.format("%d %s", i, frame.getTitle()));
            windowItem.setMnemonic(KeyEvent.VK_1 + (i - 1));
        } else {
            windowItem.setText(frame.getTitle());
        }
        windowItem.setSelected(frame.isSelected());
        windowItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    frame.setSelected(true);
                } catch (PropertyVetoException e1) {
                }
            }
        });
        mnuWindow.add(windowItem);
        ++i;
    }

}

From source file:brainflow.app.toplevel.BrainFlow.java

private MenuFactory createMenuFactory() {
    return new MenuFactory() {
        @Override//from  w  w  w  .  j a  v  a2 s  .c  o m
        public JMenu createMenu() {
            return new JideMenu();
        }

        @Override
        public JMenuItem createMenuItem() {
            return new JMenuItem();
        }

        @Override
        public JCheckBoxMenuItem createCheckBoxMenuItem() {
            return new JCheckBoxMenuItem();
        }

        @Override
        public JRadioButtonMenuItem createRadioButtonMenuItem() {
            return new JRadioButtonMenuItem();
        }

        @Override
        public JPopupMenu createPopupMenu() {
            return new JPopupMenu();
        }

        @Override
        public JMenuBar createMenuBar() {
            return new CommandMenuBar();
        }
    };

}

From source file:org.pgptool.gui.ui.mainframe.MainFrameView.java

private void initMenuBar() {
    menuBar = new JMenuBar();

    JMenu menuFile = new JMenu(Messages.get("term.appTitle"));
    menuFile.add(miChangeTempFolderForDecrypted = new JMenuItem());
    menuFile.addSeparator();/*from w  w w .  j  av  a2 s.com*/
    menuFile.add(miBmc = new JMenuItem());
    menuFile.add(miWriteFeedback = new JMenuItem());
    menuFile.add(miFaq = new JMenuItem());
    menuFile.add(miHelp = new JMenuItem());
    menuFile.addSeparator();
    menuFile.add(miAbout = new JMenuItem());
    menuFile.add(miCheckForUpdates = new JMenuItem());
    menuFile.add(miAutoCheckForUpdates = new JCheckBoxMenuItem());
    menuFile.addSeparator();
    menuFile.add(miConfigExit = new JMenuItem());

    JMenu menuKeyring = new JMenu(Messages.get("term.keyring"));
    menuKeyring.add(miShowKeyList = new JMenuItem());
    menuKeyring.addSeparator();
    menuKeyring.add(miPgpImportKey = new JMenuItem());
    menuKeyring.add(miPgpCreateKey = new JMenuItem());

    JMenu menuActions = new JMenu(Messages.get("term.actions"));
    menuActions.add(miEncrypt = new JMenuItem());
    menuActions.add(miEncryptText = new JMenuItem());
    menuActions.addSeparator();
    menuActions.add(miDecrypt = new JMenuItem());
    menuActions.add(miDecryptText = new JMenuItem());
    menuActions.addSeparator();
    menuActions.add(miEncryptBackAll = new JMenuItem());

    menuBar.add(menuFile);
    menuBar.add(menuKeyring);
    menuBar.add(menuActions);
}

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/*ww w  .  j  a va  2 s.co 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;
}

From source file:edu.pdi2.visual.PDI.java

private JCheckBoxMenuItem getJCheckBoxMIThumbs() {
    if (jCheckBoxMIThumbs == null) {
        jCheckBoxMIThumbs = new JCheckBoxMenuItem();
        jCheckBoxMIThumbs.setText("Bands Thumbnails");
        jCheckBoxMIThumbs.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent evt) {
                showThumbnails(evt);/*from  www.  j a  v  a  2  s  .  c  o  m*/
            }
        });
    }
    return jCheckBoxMIThumbs;
}

From source file:edu.pdi2.visual.PDI.java

private JCheckBoxMenuItem getJCheckBoxMISignature() {
    if (jCheckBoxMISignature == null) {
        jCheckBoxMISignature = new JCheckBoxMenuItem();
        jCheckBoxMISignature.setText("Pixel Signature");
        jCheckBoxMISignature.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jCheckBoxMISignatureActionPerformed(evt);
            }//  w  w  w  .  ja  v  a2  s  .  com
        });
    }
    return jCheckBoxMISignature;
}

From source file:edu.pdi2.visual.PDI.java

private JCheckBoxMenuItem getJViewThumnail() {
    if (jViewThumnail == null) {
        jViewThumnail = new JCheckBoxMenuItem();
        jViewThumnail.setText("Thumbnail");
        jViewThumnail.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jViewThumnailActionPerformed(evt);
            }/*  ww w .  j av a2 s .c  o m*/
        });
    }
    return jViewThumnail;
}

From source file:org.gtdfree.GTDFree.java

/**
 * This method initializes jMenu   //from  w ww.  j  ava 2s. c o m
 *    
 * @return javax.swing.JMenu   
 */
private JMenu getFileMenu() {
    if (fileMenu == null) {
        fileMenu = new JMenu();
        fileMenu.setText(Messages.getString("GTDFree.File")); //$NON-NLS-1$

        fileMenu.add(getSaveMenuItem());

        autoSaveMenuItem = new JCheckBoxMenuItem();
        autoSaveMenuItem.setText(Messages.getString("GTDFree.File.ASave")); //$NON-NLS-1$

        if (getEngine().getGTDModel().getDataRepository() instanceof GTDDataXML) {
            autoSaveMenuItem.setSelected(
                    getEngine().getGlobalProperties().getBoolean(GlobalProperties.AUTO_SAVE, true));
        } else {
            autoSaveMenuItem.setSelected(true);
            autoSaveMenuItem.setEnabled(false);
        }
        autoSaveMenuItem.setToolTipText(Messages.getString("GTDFree.File.ASave.desc")); //$NON-NLS-1$
        autoSaveMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getEngine().setAutoSave(autoSaveMenuItem.isSelected());
                getEngine().getGlobalProperties().putProperty(GlobalProperties.AUTO_SAVE,
                        autoSaveMenuItem.isSelected());
            }
        });
        fileMenu.add(autoSaveMenuItem);

        /*fileMenu.add(new JSeparator());
                
        printCurrentMenuItem= new JMenuItem();
        printCurrentMenuItem.setText("Print current view...");
        printCurrentMenuItem.setEnabled(false);
        printCurrentMenuItem.addActionListener(new ActionListener() {
                
           @Override
           public void actionPerformed(ActionEvent e) {
              WorkflowPane p= getEngine().getActiveWorkflowPane();
              if (p!=null) {
          try {
             p.printTable();
          } catch (PrinterException e1) {
             e1.printStackTrace();
             JOptionPane.showMessageDialog(getJFrame(), "Printing failed, error: "+e1.toString(), "Printing failed", JOptionPane.ERROR_MESSAGE);
          }
              }
           }
        });
                
        getEngine().addPropertyChangeListener("activePane", new PropertyChangeListener() {
                
           @Override
           public void propertyChange(PropertyChangeEvent evt) {
              printCurrentMenuItem.setEnabled(getEngine().getActiveWorkflowPane()!=null);
           }
        });
                
        fileMenu.add(printCurrentMenuItem);*/

        fileMenu.add(new JSeparator());

        JMenuItem jmi = new JMenuItem(Messages.getString("GTDFree.File.Print")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_print));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getPrintDialog().setVisible(true);
            }
        });
        fileMenu.add(jmi);

        fileMenu.add(new JSeparator());

        jmi = new JMenuItem(Messages.getString("GTDFree.File.Import")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_import));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                importFile();
            }
        });
        fileMenu.add(jmi);

        jmi = new JMenuItem(Messages.getString("GTDFree.File.Export")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_export));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getExportDialog().setVisible(true);
            }
        });
        fileMenu.add(jmi);

        jmi = new JMenuItem(Messages.getString("GTDFree.File.All")); //$NON-NLS-1$
        jmi.setToolTipText(Messages.getString("GTDFree.File.All.desc")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_export));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                exportFile();
            }
        });
        fileMenu.add(jmi);

        fileMenu.add(new JSeparator());
        fileMenu.add(getExitMenuItem());
    }
    return fileMenu;
}