Java Code Examples for javax.swing.JMenuItem#setSelected()
The following examples show how to use
javax.swing.JMenuItem#setSelected() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainFrame.java From FCMFrame with Apache License 2.0 | 6 votes |
public JMenuBar createMenus() { JMenuBar menuBar = new JMenuBar(); menuBar.getAccessibleContext().setAccessibleName(""); JMenu fileMenu = (JMenu) menuBar.add(new JMenu("文件")); createMenuItem(fileMenu, "打开文件", "", "", new OpenFileAction()); fileMenu.addSeparator(); createMenuItem(fileMenu, "保存", "", "", new SaveFileAction()); createMenuItem(fileMenu, "另存为...", "", "", new SaveAsFileAction()); fileMenu.addSeparator(); createMenuItem(fileMenu, "保存界面为图片...", "", "", new SaveAsPictureAction()); fileMenu.addSeparator(); createMenuItem(fileMenu, "打开文件位置", "", "", new FilesLocationAction()); fileMenu.addSeparator(); createMenuItem(fileMenu, "退出系统", "", "", new ExitSys()); JMenu preferenceMenu = (JMenu) menuBar.add(new JMenu("选项")); JMenuItem mi = createCheckBoxMenuItem(preferenceMenu, "显示网格", "", "", new CoordinateAction()); mi.setSelected(true); return menuBar; }
Example 2
Source File: SwingSet2.java From beautyeye with Apache License 2.0 | 6 votes |
/** * Stores the current L&F, and calls updateLookAndFeel, below. * * @param laf the new look and feel */ public void setLookAndFeel(String laf) { if(currentLookAndFeel != laf) { currentLookAndFeel = laf; /* The recommended way of synchronizing state between multiple * controls that represent the same command is to use Actions. * The code below is a workaround and will be replaced in future * version of SwingSet2 demo. */ String lafName = null; if(laf == metal) lafName = getString("LafMenu.java_label"); if(laf == gtk) lafName = getString("LafMenu.gtk_label"); if(laf == windows) lafName = getString("LafMenu.windows_label"); themesMenu.setEnabled(laf == metal); updateLookAndFeel(); for(int i=0;i<lafMenu.getItemCount();i++) { JMenuItem item = lafMenu.getItem(i); if(item.getText() == lafName) { item.setSelected(true); } else { item.setSelected(false); } } } }
Example 3
Source File: ExportFormatManager.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
private void createMenu(String selection) { menu = new JMenu(); menu.setText("Export formats"); menu.setToolTipText("Allows direct selection of export format"); buttonGroup = new ButtonGroup(); for (String formatName : toArray()) { final String name = formatName; JMenuItem menuItem = new JCheckBoxMenuItem(name); menuItem.setSelected(name.equals(selection)); menuItem.addActionListener((java.awt.event.ActionEvent evt) -> { exportFormatSelector.select(name); }); buttonGroup.add(menuItem); menu.add(menuItem); } }
Example 4
Source File: FrmMain.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
public void unloadPlugin(Plugin plugin) { if (!plugin.isLoad()) { return; } this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JMenuItem pluginMI = this.findPluginMenuItem(plugin.getName()); plugin.getPluginObject().unload(); plugin.setPluginObject(null); plugin.setLoad(false); pluginMI.setSelected(false); pluginMI.setIcon(this._unloadedPluginIcon); this.setCursor(Cursor.getDefaultCursor()); }
Example 5
Source File: StayOpenPopupMenu.java From netbeans with Apache License 2.0 | 5 votes |
private static void performAction(StayOpen item, int modifiers) { JMenuItem i = item.getItem(); // Skip disabled items if (!item.getItem().isEnabled()) return; // Handle toggle items if (i.getModel() instanceof JToggleButton.ToggleButtonModel) i.setSelected(!i.isSelected()); // Invoke item action item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED, item.getItem().getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); }
Example 6
Source File: HeapDumpOnOOMEAction.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public JMenuItem getPopupPresenter() { JMenuItem presenter = new JCheckBoxMenuItem(this); Mnemonics.setLocalizedText(presenter, NbBundle.getMessage(HeapDumpOnOOMEAction.class, "LBL_Heap_Dump_on_OOME")); // NOI18N presenter.setSelected(oomeEnabled); return presenter; }
Example 7
Source File: AutoConnectAction.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public JMenuItem getPopupPresenter() { JmxApplication app = ActionUtils.getSelectedDataSource(getScope()); currentAutoConnect = !app.isHeartbeatDisabled(); JMenuItem presenter = new JCheckBoxMenuItem(this); Mnemonics.setLocalizedText(presenter, NbBundle.getMessage(ConnectDisconnectAction.class, "LBL_AutoConnect")); // NOI18N presenter.setSelected(currentAutoConnect); return presenter; }
Example 8
Source File: StayOpenPopupMenu.java From visualvm with GNU General Public License v2.0 | 5 votes |
private static void performAction(StayOpen item, int modifiers) { JMenuItem i = item.getItem(); // Skip disabled items if (!item.getItem().isEnabled()) return; // Handle toggle items if (i.getModel() instanceof JToggleButton.ToggleButtonModel) i.setSelected(!i.isSelected()); // Invoke item action item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED, item.getItem().getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); }
Example 9
Source File: ViewMenu.java From triplea with GNU General Public License v3.0 | 5 votes |
private void addMapSkinsMenu() { final JMenu mapSubMenu = new JMenu("Map Skins"); mapSubMenu.setMnemonic(KeyEvent.VK_K); add(mapSubMenu); final ButtonGroup mapButtonGroup = new ButtonGroup(); final Map<String, String> skins = AbstractUiContext.getSkins(frame.getGame().getData()); mapSubMenu.setEnabled(skins.size() > 1); for (final String key : skins.keySet()) { final JMenuItem mapMenuItem = new JRadioButtonMenuItem(key); mapButtonGroup.add(mapMenuItem); mapSubMenu.add(mapMenuItem); if (skins.get(key).equals(AbstractUiContext.getMapDir())) { mapMenuItem.setSelected(true); } mapMenuItem.addActionListener( e -> { try { frame.updateMap(skins.get(key)); if (uiContext.getMapData().getHasRelief()) { showMapDetails.setSelected(true); } showMapDetails.setEnabled(uiContext.getMapData().getHasRelief()); } catch (final Exception exception) { log.log(Level.SEVERE, "Error Changing Map Skin2", exception); } }); } }
Example 10
Source File: AbstractRadioListMenu.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public void setSelectedItem(E item) { JMenuItem menuItem = menuMap.get(item); if (menuItem != null) { menuItem.setSelected(true); } selectedItem = item; }
Example 11
Source File: ExportFormatManager.java From IrScrutinizer with GNU General Public License v3.0 | 5 votes |
public void setMenuSelection(String format) { if (menu == null) createMenu(format); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem item = menu.getItem(i); item.setSelected(item.getText().equals(format)); } }
Example 12
Source File: CheckWikiWindow.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Update popup menu for selecting errors. */ private void updatePopupSelectErrors() { for (CheckErrorAlgorithm algorithm : allAlgorithms) { if (algorithm != null) { int errorNumber = algorithm.getErrorNumber(); if (errorNumber < menuItemAlgorithms.size()) { JMenuItem menuItem = menuItemAlgorithms.get(errorNumber); if (menuItem != null) { menuItem.setSelected(selectedAlgorithms.contains(algorithm)); } } } } }
Example 13
Source File: JPin.java From firmata4j with MIT License | 5 votes |
public final void setModel(final Pin model) { if (this.model != null) { this.model.removeEventListener(this); modesMenu.removeAll(); } this.model = model; ButtonGroup group = new ButtonGroup(); for (Pin.Mode mode : model.getSupportedModes()) { Action action = new AbstractAction(mode.name()) { @Override public void actionPerformed(ActionEvent e) { try { model.setMode((Pin.Mode) getValue("mode")); } catch (IOException ex) { JOptionPane.showMessageDialog(JPin.this, ex.getLocalizedMessage(), "", JOptionPane.ERROR_MESSAGE); } } }; action.putValue("mode", mode); JMenuItem item = new JRadioButtonMenuItem(action); item.setSelected(model.getMode() == mode); group.add(item); modesMenu.add(item); } model.addEventListener(this); refreshIcon(); }
Example 14
Source File: AbstractRadioListMenu.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public void setSelectedItem(E item) { JMenuItem menuItem = menuMap.get(item); if (menuItem != null) { menuItem.setSelected(true); } selectedItem = item; }
Example 15
Source File: OSPLog.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Sets the logger level. * * @param level the Level */ public static void setLevel(Level level) { if(OSPRuntime.appletMode||(OSPRuntime.applet!=null)) { org.opensourcephysics.controls.MessageFrame.setLevel(level); } else { try { getOSPLog().getLogger().setLevel(level); } catch(Exception ex) { // throws security exception if the caller does not have LoggingPermission("control"). // keep the current level } // refresh the level menus if the menubar exists if((getOSPLog()==null)||(getOSPLog().menubarGroup==null)) { return; } for(int i = 0; i<2; i++) { Enumeration<AbstractButton> e = getOSPLog().menubarGroup.getElements(); if(i==1) { e = getOSPLog().popupGroup.getElements(); } while(e.hasMoreElements()) { JMenuItem item = (JMenuItem) e.nextElement(); if(getOSPLog().getLogger().getLevel().toString().equals(item.getActionCommand())) { item.setSelected(true); break; } } } } }
Example 16
Source File: SortAction.java From netbeans with Apache License 2.0 | 4 votes |
private JMenuItem createItem(String dispName, boolean selected) { JMenuItem item = new JRadioButtonMenuItem(); item.setText(dispName); item.setSelected(selected); return item; }