List of usage examples for javax.swing JCheckBoxMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:JCheckBoxMenuItemActionListener.java
public static void main(final String args[]) { JFrame frame = new JFrame(); 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 www.j ava 2s .c om*/ // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive"); caseMenuItem.setMnemonic(KeyEvent.VK_C); fileMenu.add(caseMenuItem); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); String newLabel; Icon newIcon; if (selected) { newLabel = "A"; } else { newLabel = "B"; } aButton.setText(newLabel); } }; caseMenuItem.addActionListener(aListener); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:net.sf.firemox.stack.EventManager.java
/** * Create an instance of MEventManager by reading a file * //from w w w . j av a 2 s .c om * @since 0.31 graphical representation of phases for both players */ public static void init() { MPhase.optionsMenu = new JPopupMenu(); JCheckBoxMenuItem item = new JCheckBoxMenuItem(LanguageManager.getString("breakpoint"), new javax.swing.ImageIcon(IdConst.IMAGES_DIR + "breakpoint.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("breakpoint.tooltip")); item.setMnemonic('b'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setBreakpoint(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhase"), UIHelper.getIcon("skipall1.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhase.tooltip")); item.setMnemonic('l'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAll(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseOnce"), UIHelper.getIcon("skipall2.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseOnce.tooltip") + "<br><br>" + MagicUIComponents.HTML_ICON_TIP + LanguageManager.getString("skipPhaseOnceTTtip")); item.setMnemonic('o'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseMedium"), UIHelper.getIcon("skipallm2.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseMedium.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('m'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipMedium(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseMediumOnce"), UIHelper.getIcon("skipallm.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseMediumOnce.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('p'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipMediumTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseAll"), UIHelper.getIcon("skipall3.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseAll.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('u'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllVery(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseAllOnce"), UIHelper.getIcon("skipall4.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseAllOnce.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('t'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllVeryTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); }
From source file:org.esa.beam.visat.toolviews.stat.MaskSelectionToolSupport.java
public JCheckBoxMenuItem createMaskSelectionModeMenuItem() { final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(String.format("Select Mask '%s'", maskName)); menuItem.setName("maskSelectionMode"); menuItem.addActionListener(new ActionListener() { @Override/*www . j av a2 s .c o m*/ public void actionPerformed(ActionEvent e) { if (menuItem.isSelected()) { if (plotAreaSelectionTool == null) { plotAreaSelectionTool = new PlotAreaSelectionTool(chartPanel, MaskSelectionToolSupport.this); plotAreaSelectionTool.setAreaType(areaType); plotAreaSelectionTool.setFillPaint(createAlphaColor(maskColor, 50)); } plotAreaSelectionTool.install(); } else { if (plotAreaSelectionTool != null) { plotAreaSelectionTool.uninstall(); } } } }); return menuItem; }
From source file:Main.java
public Main() { menuBar = new JMenuBar(); JMenu justifyMenu = new JMenu("Justify"); ActionListener actionPrinter = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Action [" + e.getActionCommand() + "] performed!\n"); }/* w w w. j av a 2s .c o m*/ }; JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif")); leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT); leftJustify .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); leftJustify.addActionListener(actionPrinter); JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif")); rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT); rightJustify .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); rightJustify.addActionListener(actionPrinter); JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif")); centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT); centerJustify .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); centerJustify.addActionListener(actionPrinter); JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif")); fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT); fullJustify .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fullJustify.addActionListener(actionPrinter); justifyMenu.add(leftJustify); justifyMenu.add(rightJustify); justifyMenu.add(centerJustify); justifyMenu.add(fullJustify); menuBar.add(justifyMenu); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); }
From source file:CheckBoxMenuItemExample.java
public CheckBoxMenuItemExample() { menuBar = new JMenuBar(); JMenu justifyMenu = new JMenu("Justify"); ActionListener actionPrinter = new ActionListener() { public void actionPerformed(ActionEvent e) { try { pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n", null);//from w w w . j a v a 2 s .co m } catch (Exception ex) { ex.printStackTrace(); } } }; JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif")); leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT); leftJustify .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); leftJustify.addActionListener(actionPrinter); JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif")); rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT); rightJustify .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); rightJustify.addActionListener(actionPrinter); JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif")); centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT); centerJustify .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); centerJustify.addActionListener(actionPrinter); JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif")); fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT); fullJustify .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fullJustify.addActionListener(actionPrinter); justifyMenu.add(leftJustify); justifyMenu.add(rightJustify); justifyMenu.add(centerJustify); justifyMenu.add(fullJustify); menuBar.add(justifyMenu); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); }
From source file:InternalFrameTest.java
public DesktopFrame() { setTitle("InternalFrameTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); desktop = new JDesktopPane(); add(desktop, BorderLayout.CENTER); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/* w w w. j av a 2 s. c o m*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem openItem = new JMenuItem("New"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { createInternalFrame(new JLabel(new ImageIcon(planets[counter] + ".gif")), planets[counter]); counter = (counter + 1) % planets.length; } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenu windowMenu = new JMenu("Window"); menuBar.add(windowMenu); JMenuItem nextItem = new JMenuItem("Next"); nextItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { selectNextWindow(); } }); windowMenu.add(nextItem); JMenuItem cascadeItem = new JMenuItem("Cascade"); cascadeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { cascadeWindows(); } }); windowMenu.add(cascadeItem); JMenuItem tileItem = new JMenuItem("Tile"); tileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { tileWindows(); } }); windowMenu.add(tileItem); final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem("Drag Outline"); dragOutlineItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE : JDesktopPane.LIVE_DRAG_MODE); } }); windowMenu.add(dragOutlineItem); }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the Statistics Menu, showing all available statistics for the * chosen ChartableKstat./* w w w .j av a 2 s . c o m*/ * * @param cks the Kstat to show the statistics of in the menu * @param statistic the initial statistic, which will be checked * * @return the Statistics Menu */ protected JMenu statisticsMenu(ChartableKstat cks, String statistic) { JMenu jmstat = new JMenu(KstatResources.getString("CHART.SHOW")); jmstat.setMnemonic(KeyEvent.VK_S); for (String stat : cks.getStatistics()) { JCheckBoxMenuItem jmi = new JCheckBoxMenuItem(stat, stat.equals(statistic)); jmi.addActionListener(this); jmstat.add(jmi); } return jmstat; }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the Statistics Menu, showing all available statistics for the * chosen ChartableKstat.//from ww w. ja v a 2s .c om * * @param cks the ChartableKstat to show the statistics of in the menu * @param statistics the initial statistics, which will be checked * * @return the Statistics Menu */ protected JMenu statisticsMenu(ChartableKstat cks, List<String> statistics) { JMenu jmstat = new JMenu(KstatResources.getString("CHART.SHOW")); jmstat.setMnemonic(KeyEvent.VK_S); for (String stat : cks.getStatistics()) { JCheckBoxMenuItem jmi = new JCheckBoxMenuItem(stat, statistics.contains(stat)); jmi.addActionListener(this); jmstat.add(jmi); } return jmstat; }
From source file:de.hstsoft.sdeep.view.MainWindow.java
private void createUI() { mapView = new MapView(); getContentPane().add(mapView, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);//ww w.j a v a 2s . c om JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmOpenSaveGame = new JMenuItem("Open Savegame"); mntmOpenSaveGame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFileChooser(); } }); mnFile.add(mntmOpenSaveGame); mnFile.addSeparator(); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); mnFile.add(mntmExit); JMenu mnView = new JMenu("View"); menuBar.add(mnView); final JCheckBoxMenuItem menuItemShowinfo = new JCheckBoxMenuItem("ShowInfo"); menuItemShowinfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showInfo = menuItemShowinfo.isSelected(); mapView.setShowInfo(showInfo); } }); menuItemShowinfo.setSelected(mapView.isShowInfo()); mnView.add(menuItemShowinfo); final JCheckBoxMenuItem menuItemShowgrid = new JCheckBoxMenuItem("ShowGrid"); menuItemShowgrid.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showGrid = menuItemShowgrid.isSelected(); mapView.setShowGrid(showGrid); } }); menuItemShowgrid.setSelected(mapView.isShowGrid()); mnView.add(menuItemShowgrid); final JCheckBoxMenuItem menuItemNotes = new JCheckBoxMenuItem("ShowNotes"); menuItemNotes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showNotes = menuItemNotes.isSelected(); mapView.setShowNotes(showNotes); } }); menuItemNotes.setSelected(mapView.isShowNotes()); mnView.add(menuItemNotes); final JCheckBoxMenuItem menuItemAnimals = new JCheckBoxMenuItem("ShowAnimals"); menuItemAnimals.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showAnimals = menuItemAnimals.isSelected(); mapView.setShowAnimals(showAnimals); } }); menuItemAnimals.setSelected(mapView.isShowAnimals()); mnView.add(menuItemAnimals); mnView.addSeparator(); menuItemFileWatcher = new JCheckBoxMenuItem("Auto refresh"); menuItemFileWatcher.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean enabled = menuItemFileWatcher.isSelected(); toggleAutoRefresh(enabled); } }); mnView.add(menuItemFileWatcher); mnView.addSeparator(); JMenuItem menuItemResetView = new JMenuItem("Reset view"); menuItemResetView.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapView.resetView(); } }); mnView.add(menuItemResetView); JMenu mnInfo = new JMenu("Info"); menuBar.add(mnInfo); JMenuItem mntmInfo = new JMenuItem("About"); mntmInfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showInfo(); } }); mnInfo.add(mntmInfo); }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JCheckBoxMenuItem getIntelCheckBoxMenuItem(String text) { final JCheckBoxMenuItem box = new JCheckBoxMenuItem(text, UIImages.EMPTY_BOX_ICON.getImageIcon()); // should do it through L&F, but couldn't find the way to do it // so we are using action listener to dynamically change icon box.addActionListener(new ActionListener() { @Override//from w w w . j a v a2 s .c om public void actionPerformed(ActionEvent e) { box.setIcon(box.isSelected() ? UIImages.CHECK_BOX_ICON.getImageIcon() : UIImages.EMPTY_BOX_ICON.getImageIcon()); } }); return box; }