List of usage examples for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem
public JCheckBoxMenuItem(Action a)
From source file:MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from ww w .j a v a 2 s . com*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); // a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); // a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); // a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); // a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); // Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderJoinCondition.java
private void createPopupMenu() { bindingGroup = new BindingGroup(); menu = new JPopupMenu("Popup menu"); JMenuItem item1;/*from w ww . j a va2s . c o m*/ JCheckBoxMenuItem item2; JCheckBoxMenuItem item3; JCheckBoxMenuItem item4; item1 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE)); item1.setActionCommand(DELETE); item1.addActionListener(this); item2 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MANDATORY)); Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${mandatory}"), item2, BeanProperty.create("selected")); bindingGroup.addBinding(binding); item2.setActionCommand(TOGGLE_MANDATORY); item2.addActionListener(this); item3 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_FOREIGN)); Binding binding2 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${monodirectional}"), item3, BeanProperty.create("selected")); bindingGroup.addBinding(binding2); item3.setActionCommand(TOGGLE_FOREIGN); item3.addActionListener(this); item4 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MATCH_STRING)); Binding binding3 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${matchString}"), item4, BeanProperty.create("selected")); bindingGroup.addBinding(binding3); item4.setActionCommand(TOGGLE_MATCH_STRING); item4.addActionListener(this); menu.add(item1); menu.add(item2); menu.add(item3); menu.add(item4); bindingGroup.bind(); }
From source file:MenuDemo.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu("File"); menuFile.setMnemonic('f'); JMenuItem menuItem = new JMenuItem("New"); menuItem.setIcon(new ImageIcon("file_new.gif")); menuItem.setMnemonic('n'); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("New"); }//from w ww .j a v a 2 s .co m }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Open..."); menuItem.setIcon(new ImageIcon("file_open.gif")); menuItem.setMnemonic('o'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuDemo.this.repaint(); if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION) return; System.out.println(fileChooser.getSelectedFile()); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Save..."); menuItem.setIcon(new ImageIcon("file_save.gif")); menuItem.setMnemonic('s'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Save..."); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuFile.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.setMnemonic('x'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuBar.add(menuFile); ActionListener fontListener = new ActionListener() { public void actionPerformed(ActionEvent e) { updateMonitor(); } }; JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); menus = new JMenuItem[FontNames.length]; for (int i = 0; i < FontNames.length; i++) { int m = i + 1; menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]); boolean selected = (i == 0); menus[i].setSelected(selected); menus[i].setMnemonic('1' + i); menus[i].setFont(fontArray[i]); menus[i].addActionListener(fontListener); group.add(menus[i]); mFont.add(menus[i]); } mFont.addSeparator(); boldMenuItem = new JCheckBoxMenuItem("Bold"); boldMenuItem.setMnemonic('b'); Font fn = fontArray[1].deriveFont(Font.BOLD); boldMenuItem.setFont(fn); boldMenuItem.setSelected(false); boldMenuItem.addActionListener(fontListener); mFont.add(boldMenuItem); italicMenuItem = new JCheckBoxMenuItem("Italic"); italicMenuItem.setMnemonic('i'); fn = fontArray[1].deriveFont(Font.ITALIC); italicMenuItem.setFont(fn); italicMenuItem.setSelected(false); italicMenuItem.addActionListener(fontListener); mFont.add(italicMenuItem); menuBar.add(mFont); return menuBar; }
From source file:components.MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*w w w . j av a 2 s . c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:components.MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from www . j av a 2 s . c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }
From source file:MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from w w w .ja va 2s . c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from w w w . ja v a 2 s . c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }
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);/* www .j ava2 s. c o m*/ 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.sshtools.appframework.api.ui.ActionBuilder.java
protected void rebuildContextMenu(Collection<AppAction> enabledActions) { contextMenu.invalidate();//w w w. j av a2s . c o m // Build the context menu action list List<AppAction> contextMenuActions = new ArrayList<AppAction>(); contextMenu.removeAll(); for (AppAction action : enabledActions) { if (Boolean.TRUE.equals(action.getValue(AppAction.ON_CONTEXT_MENU))) { contextMenuActions.add(action); } } log.debug("There are " + contextMenuActions.size() + " on the context menu"); Collections.sort(contextMenuActions, new ContextActionComparator()); // Build the context menu Integer grp = null; for (AppAction action : contextMenuActions) { if ((grp != null) && !grp.equals(action.getValue(AppAction.CONTEXT_MENU_GROUP))) { contextMenu.addSeparator(); } if (Boolean.TRUE.equals(action.getValue(AppAction.IS_TOGGLE_BUTTON))) { final JCheckBoxMenuItem item = new JCheckBoxMenuItem(action); action.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(AppAction.IS_SELECTED)) { item.setSelected(((Boolean) evt.getNewValue()).booleanValue()); } } }); contextMenu.add(item); item.setSelected(Boolean.TRUE.equals(action.getValue(AppAction.IS_SELECTED))); } else { contextMenu.add(action); } grp = (Integer) action.getValue(AppAction.CONTEXT_MENU_GROUP); } contextMenu.validate(); contextMenu.repaint(); }
From source file:de.ailis.xadrian.components.ComplexEditor.java
/** * Constructor/*from www.ja v a2s . co m*/ * * @param complex * The complex to edit * @param file * The file from which the complex was loaded. Null if it not * loaded from a file. */ public ComplexEditor(final Complex complex, final File file) { super(); setLayout(new BorderLayout()); this.complex = complex; this.file = file; // Create the text pane this.textPane = new JTextPane(); this.textPane.setEditable(false); this.textPane.setBorder(null); this.textPane.setContentType("text/html"); this.textPane.setDoubleBuffered(true); this.textPane.addHyperlinkListener(this); this.textPane.addCaretListener(this); // Create the popup menu for the text pane final JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new CopyAction(this)); popupMenu.add(new SelectAllAction(this)); popupMenu.addSeparator(); popupMenu.add(new AddFactoryAction(this)); popupMenu.add(new ChangeSectorAction(this.complex, this, "complex")); popupMenu.add(new ChangeSunsAction(this)); popupMenu.add(new ChangePricesAction(this)); popupMenu.add(new JCheckBoxMenuItem(new ToggleBaseComplexAction(this))); SwingUtils.setPopupMenu(this.textPane, popupMenu); final HTMLDocument document = (HTMLDocument) this.textPane.getDocument(); // Set the base URL of the text pane document.setBase(Main.class.getResource("templates/")); // Modify the body style so it matches the system font final Font font = UIManager.getFont("Label.font"); final String bodyRule = "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }"; document.getStyleSheet().addRule(bodyRule); // Create the scroll pane final JScrollPane scrollPane = new JScrollPane(this.textPane); add(scrollPane); // Redraw the content redraw(); fireComplexState(); }