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(String text, Icon icon, boolean b) 

Source Link

Document

Creates a check box menu item with the specified text, icon, and selection state.

Usage

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from   w ww  . ja  v  a2  s  . c  o m

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Item", new MyIcon(Color.RED), true);
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:de.dakror.virtualhub.server.ServerFrame.java

public void init() {
    initFiles();// w w w.  j  av a 2  s .  co  m

    logArea = new JTextArea();
    logArea.setWrapStyleWord(true);
    logArea.setEditable(false);
    logArea.setLineWrap(true);
    DefaultCaret caret = (DefaultCaret) logArea.getCaret();
    caret.setSelectionVisible(false);
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    wrap = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    setContentPane(wrap);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Aktionen");
    menu.add(new JMenuItem(
            new AbstractAction("Protokoll leeren", new ImageIcon(getClass().getResource("/img/trash.png"))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    logArea.setText("");
                    log("Protokoll geleert.");
                }
            }));
    menu.add(logEnabled = new JCheckBoxMenuItem("Protokoll aktiviert",
            new ImageIcon(getClass().getResource("/img/log.png")), true));
    menu.add(packetLogEnabled = new JCheckBoxMenuItem("Paketverkehr protokollieren",
            new ImageIcon(getClass().getResource("/img/traffic.png")), false));
    menu.addSeparator();
    menu.add(new JMenuItem(new AbstractAction("Backup-Einstellungen",
            new ImageIcon(getClass().getResource("/img/backup_edit.png"))) {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                BackupEditDialog.show();
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }));

    menuBar.add(menu);
    setJMenuBar(menuBar);
}