javax.swing.JMenu Java Examples
The following examples show how to use
javax.swing.JMenu.
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: bug8031573.java From dragonwell8_jdk with GNU General Public License v2.0 | 7 votes |
@Override public void init() { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Menu"); JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem("JCheckBoxMenuItem"); checkBoxMenuItem.setSelected(true); menu.add(checkBoxMenuItem); bar.add(menu); setJMenuBar(bar); } }); } catch (Exception e) { throw new RuntimeException(e); } }
Example #2
Source File: GltfBrowserApplication.java From JglTF with MIT License | 6 votes |
/** * Create the file menu * * @return The file menu */ private JMenu createFileMenu() { JMenu fileMenu = new JMenu("File"); fileMenu.add(new JMenuItem(openFileAction)); fileMenu.add(new JMenuItem(openUriAction)); fileMenu.add(new JSeparator()); fileMenu.add(recentUrisMenu.getMenu()); fileMenu.add(new JSeparator()); fileMenu.add(new JMenuItem(importObjFileAction)); fileMenu.add(new JSeparator()); fileMenu.add(new JMenuItem(saveAsAction)); fileMenu.add(new JMenuItem(saveAsBinaryAction)); fileMenu.add(new JMenuItem(saveAsEmbeddedAction)); fileMenu.add(new JSeparator()); fileMenu.add(new JMenuItem(exitAction)); return fileMenu; }
Example #3
Source File: ComboMenuBar.java From ChatGameFontificator with The Unlicense | 6 votes |
private void setup(final JMenu menu) { Color color = UIManager.getColor("Menu.selectionBackground"); UIManager.put("Menu.selectionBackground", UIManager.getColor("Menu.background")); menu.updateUI(); UIManager.put("Menu.selectionBackground", color); ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JMenuItem item = (JMenuItem) e.getSource(); menu.setText(item.getText()); menu.requestFocus(); } }; setListener(menu, listener); add(menu); }
Example #4
Source File: AmidstMenuBuilder.java From amidst with GNU General Public License v3.0 | 6 votes |
private JMenu create_Settings() { JMenu result = new JMenu("Settings"); result.setMnemonic(KeyEvent.VK_S); result.add(create_Settings_DefaultWorldType()); if (biomeProfileDirectory.isValid()) { result.add(create_Settings_BiomeProfile()); } result.addSeparator(); // @formatter:off Menus.checkbox(result, settings.smoothScrolling, "Smooth Scrolling"); Menus.checkbox(result, settings.fragmentFading, "Fragment Fading"); Menus.checkbox(result, settings.maxZoom, "Restrict Maximum Zoom"); Menus.checkbox(result, settings.showFPS, "Show Framerate & CPU"); Menus.checkbox(result, settings.showScale, "Show Scale"); Menus.checkbox(result, settings.showDebug, "Show Debug Information"); // @formatter:on result.addSeparator(); result.add(create_Settings_LookAndFeel()); return result; }
Example #5
Source File: OutputTab.java From netbeans with Apache License 2.0 | 6 votes |
private void addFoldingActionsToPopUpMenu(JPopupMenu menu, List<TabAction> activeActions) { JMenu submenu = new JMenu(NbBundle.getMessage( OutputTab.class, "LBL_OutputFolds")); //NOI18N for (ACTION a : popUpFoldItems) { if (a == null) { submenu.addSeparator(); } else { TabAction ta = action(a); activeActions.add(ta); submenu.add(new JMenuItem(ta)); } } menu.addSeparator(); menu.add(submenu); }
Example #6
Source File: AbstractMenuCreator.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Add an item to a menu. * * @param menu Menu. * @param page Page. * @param title Element title (if null, the page title will be used). * @param asIs True if the message should be used as is (no mnemonic). * @param action Action. * @param accelerator Accelerator. * @return Number of items added. */ public int addItem( JMenu menu, Page page, String title, boolean asIs, ActionListener action, KeyStroke accelerator) { if (menu == null) { return 0; } if ((title == null) && ((page == null) || (page.getTitle() == null))) { return 0; } JMenuItem menuItem = Utilities.createJMenuItem(title != null ? title : page.getTitle(), asIs); if (page != null) { updateFont(menuItem, page); } if (action != null) { menuItem.addActionListener(action); } if (accelerator != null) { menuItem.setAccelerator(accelerator); } menu.add(menuItem); return 1; }
Example #7
Source File: GUIFrame.java From jaamsim with Apache License 2.0 | 6 votes |
/** * Sets up the Help menu in the Control Panel's menu bar. */ private void initializeHelpMenu() { // Help menu creation helpMenu = new JMenu( "Help" ); helpMenu.setMnemonic(KeyEvent.VK_H); // 1) "About" menu item JMenuItem aboutMenu = new JMenuItem( "About" ); aboutMenu.setMnemonic(KeyEvent.VK_A); aboutMenu.addActionListener( new ActionListener() { @Override public void actionPerformed( ActionEvent event ) { AboutBox.instance().setVisible(true); } } ); helpMenu.add( aboutMenu ); }
Example #8
Source File: DynaMenuModelTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * Test of checkSubmenu method, of class org.openide.awt.DynaMenuModel. */ public void testCheckSubmenu() { List<Object> cInstances = new ArrayList<Object>(); cInstances.add(new Act1()); cInstances.add(new Act2()); JMenu m = new JMenu(); DynaMenuModel instance = new DynaMenuModel(); instance.loadSubmenu(cInstances, m, false, Collections.<Object,FileObject>emptyMap()); instance.checkSubmenu(m); Component[] comps = m.getPopupMenu().getComponents(); assertEquals("0", ((JMenuItem)comps[0]).getText()); assertEquals("1x", ((JMenuItem)comps[1]).getText()); assertEquals("2x", ((JMenuItem)comps[2]).getText()); }
Example #9
Source File: SendingHardwareManager.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
private void createMenu(String selection) { menu = new JMenu(); menu.setText("Transmitting Hardware"); menu.setToolTipText("Allows direct selection of transmitting hardware"); buttonGroup = new ButtonGroup(); table.entrySet().stream().map((kvp) -> { String name = kvp.getKey(); final ISendingHardware<?> hardware = kvp.getValue(); JRadioButton menuItem = new JRadioButton(name); menuItem.setSelected(name.equals(selection)); //portRadioButtons[i] = menuItem; menuItem.addActionListener((java.awt.event.ActionEvent evt) -> { try { select(hardware); } catch (HarcHardwareException ex) { guiUtils.error(ex); } }); return menuItem; }).map((menuItem) -> { buttonGroup.add(menuItem); return menuItem; }).forEachOrdered((menuItem) -> { menu.add(menuItem); }); }
Example #10
Source File: PCGenMenuBar.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private JMenu createSourcesMenu() { JMenu menu = new JMenu(); menu.setText(LanguageBundle.getString("in_mnuSources")); menu.setToolTipText(LanguageBundle.getString("in_mnuSourcesTip")); menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_LOAD_SELECT_COMMAND))); menu.addSeparator(); menu.add(new QuickSourceMenu()); menu.addSeparator(); menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_RELOAD_COMMAND))); menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_UNLOAD_COMMAND))); menu.addSeparator(); menu.add(actionMap.get(PCGenActionMap.INSTALL_DATA_COMMAND)); return menu; }
Example #11
Source File: MobileORTable.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void init() { JMenu setPriority = new JMenu("Set Priority"); JMenu addProp = new JMenu("Add Property"); JMenu clearProp = new JMenu("Clear Property"); JMenu deleteProp = new JMenu("Remove Property"); setPriority.add(Utils.createMenuItem("Set Priority to Page", MobileORTable.this)); setPriority.add(Utils.createMenuItem("Set Priority to All", MobileORTable.this)); setPriority.add(Utils.createMenuItem("Set Priority to Selected", MobileORTable.this)); add(setPriority); clearProp.add(Utils.createMenuItem("Clear from Page", MobileORTable.this)); clearProp.add(Utils.createMenuItem("Clear from All", MobileORTable.this)); clearProp.add(Utils.createMenuItem("Clear from Selected", MobileORTable.this)); add(clearProp); deleteProp.add(Utils.createMenuItem("Remove from Page", MobileORTable.this)); deleteProp.add(Utils.createMenuItem("Remove from All", MobileORTable.this)); deleteProp.add(Utils.createMenuItem("Remove from Selected", MobileORTable.this)); add(deleteProp); addProp.add(Utils.createMenuItem("Add to Page", MobileORTable.this)); addProp.add(Utils.createMenuItem("Add to All", MobileORTable.this)); addProp.add(Utils.createMenuItem("Add to Selected", MobileORTable.this)); add(addProp); }
Example #12
Source File: WindowMenu.java From pumpernickel with MIT License | 6 votes |
/** * On Mac often the menus won't really update without this hack-ish twist: * remove the menu and re-add it. Voila! It's both unnecessary and crucial * at the same time. * * @param f * the frame whose menubar you need to update. * @param menu * the menu you need to update. */ static void fixMenuBar(JFrame f, JMenu menu) { JMenuBar mb = f.getJMenuBar(); if (mb != null) { JMenu[] menus = new JMenu[mb.getMenuCount()]; for (int a = 0; a < menus.length; a++) { menus[a] = mb.getMenu(a); } boolean found = false; List<JMenu> menusToAdd = new ArrayList<>(); for (int a = 0; a < menus.length; a++) { if (menus[a] == menu) found = true; if (found) { mb.remove(menus[a]); menusToAdd.add(menus[a]); } } for (JMenu menuToAdd : menusToAdd) { mb.add(menuToAdd); } } }
Example #13
Source File: PLAF.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * */ private void addToMenu(String name, String className, JMenu menu) { logger.debug("PLAF LookAndFeelInfo {}", className); boolean isSupported = true; try { Class cl = Class.forName(className); LookAndFeel lf = (LookAndFeel) cl.newInstance(); if (!lf.isSupportedLookAndFeel()) { isSupported = false; } } catch (Throwable t) { isSupported = false; } AbstractAction act = new PLAFAction(name, className); JMenuItem mi = menu.add(act); if (!isSupported) { mi.setEnabled(false); } }
Example #14
Source File: LanguagesGenerateFoldPopupAction.java From netbeans with Apache License 2.0 | 6 votes |
private void addFoldTypes (JTextComponent target, JMenu menu, Language language, Set expands) { List<Feature> features = language.getFeatureList ().getFeatures (LanguagesFoldManager.FOLD); Iterator<Feature> it = features.iterator (); while (it.hasNext ()) { Feature fold = it.next (); String expand = LocalizationSupport.localize (language, (String) fold.getValue ("expand_type_action_name")); if (expand == null) continue; if (expands.contains (expand)) continue; expands.add (expand); String collapse = LocalizationSupport.localize (language, (String) fold.getValue ("collapse_type_action_name")); if (collapse == null) continue; addAction (target, menu, EXPAND_PREFIX + expand); addAction (target, menu, COLLAPSE_PREFIX + collapse); setAddSeparatorBeforeNextAction (true); } }
Example #15
Source File: MainFrame.java From android-screen-monitor with Apache License 2.0 | 6 votes |
private void addRadioButtonMenuItemZoom( JMenu menuZoom, ButtonGroup buttonGroup, final double zoom, String caption, int nemonic, double currentZoom) { JRadioButtonMenuItem radioButtonMenuItemZoom = new JRadioButtonMenuItem(caption); if (nemonic != -1) { radioButtonMenuItemZoom.setMnemonic(nemonic); } radioButtonMenuItemZoom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setZoom(zoom); } }); if (currentZoom == zoom) { radioButtonMenuItemZoom.setSelected(true); } buttonGroup.add(radioButtonMenuItemZoom); menuZoom.add(radioButtonMenuItemZoom); }
Example #16
Source File: InternalFrameDemoFrame.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); //Set up the lone menu. final JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu); menu.add(new JMenuItem(new NewFrameAction())); menu.add(new JMenuItem(getPreviewAction())); menu.addSeparator(); menu.add(new JMenuItem(getCloseAction())); final JMenu helpmenu = new JMenu("Help"); helpmenu.setMnemonic(KeyEvent.VK_H); helpmenu.add(new JMenuItem(getAboutAction())); return menuBar; }
Example #17
Source File: BranchMenu.java From netbeans with Apache License 2.0 | 5 votes |
@Override public JMenuItem getPopupPresenter() { JMenu menu = createMenu(); menu.setText(Bundle.CTL_MenuItem_BranchMenu_popupName()); enableMenu(menu); return menu; }
Example #18
Source File: MisplacedBorder.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public void run() { final JMenuBar menubar = new JMenuBar(); menubar.add(new JMenu("")); menubar.add(new JMenu("")); final JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setJMenuBar(menubar); frame.setSize(W / 3, H / 3); frame.setLocationRelativeTo(null); frame.setVisible(true); // draw menu bar using standard order. final BufferedImage bi1 = step1(menubar); // draw menu border on top of the menu bar, nothing should be changed. final BufferedImage bi2 = step2(menubar); frame.dispose(); for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { try { ImageIO.write(bi1, "png", new File("image1.png")); ImageIO.write(bi2, "png", new File("image2.png")); } catch (IOException e) { e.printStackTrace(); } throw new RuntimeException("Failed: wrong color"); } } } }
Example #19
Source File: OculusViewBuilder.java From arcusplatform with Apache License 2.0 | 5 votes |
@Inject public OculusViewBuilder( List<ComponentWrapper<JMenu>> menus, List<OculusSection> sections ) { this.menus = menus; this.sections = sections; }
Example #20
Source File: Methods.java From knife with MIT License | 5 votes |
public static JMenu add_MenuItem_and_listener(JMenu menu, String[] itemList, Object actionListener){ for(int i = 0; i < itemList.length; i++){ JMenuItem item = new JMenuItem(itemList[i]); item.addActionListener((ActionListener) actionListener); menu.add(item); } return menu; }
Example #21
Source File: CRegisterTrackingExtension.java From binnavi with Apache License 2.0 | 5 votes |
@Override public void extendOutgoingRegistersMenu(final JMenu menu, final INaviCodeNode node, final INaviInstruction instruction, final String register) { menu.add(CActionProxy.proxy(new CTrackOperandAction(m_resultsContainer, instruction, register, new RegisterTrackingOptions(m_settingsPanel.doClearAllRegisters(), m_settingsPanel.getClearedRegisters(), false, AnalysisDirection.DOWN)))); menu.add(CActionProxy.proxy(new CTrackOperandAction(m_resultsContainer, instruction, register, new RegisterTrackingOptions(m_settingsPanel.doClearAllRegisters(), m_settingsPanel.getClearedRegisters(), false, AnalysisDirection.UP)))); }
Example #22
Source File: Window.java From lippen-network-tool with Apache License 2.0 | 5 votes |
private void initMenu() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("设置(O)"); menu.setMnemonic('O'); JMenu m = new JMenu("编码设置(E)"); ButtonGroup group = new ButtonGroup(); for (String[] charset : charsets) { if (charset.length == 0) { m.addSeparator(); continue; } CharsetCheckBoxMenuItem item = new CharsetCheckBoxMenuItem(charset[0], charset[1]); if (charset[1].equals(DEFAULT_CHARSET.name())) { item.setSelected(true); } item.addActionListener(listener); group.add(item); m.add(item); } menu.add(m); JMenu about = new JMenu("关于"); menuBar.add(menu); menuBar.add(about); this.setJMenuBar(menuBar); }
Example #23
Source File: MainFrame.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Removes duplicated separators from a JMenu * * @param menu the menu */ private static void removeDuplicatedSeparators(JMenu menu) { int separatorCount = 0; for (Component component : menu.getMenuComponents()) { if (component instanceof JPopupMenu.Separator) { separatorCount++; } else { separatorCount = 0; } if (separatorCount > 1) { menu.remove(component); } } }
Example #24
Source File: EditorRootPane.java From libGDX-Path-Editor with Apache License 2.0 | 5 votes |
private JMenu createProjectMenu() { JMenu menu = new JMenu(MenuConsts.project); newProjectItem = new JMenuItem(MenuConsts.newProject); newProjectItem.addActionListener(menuHandler); newProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_newProject))); menu.add(newProjectItem); openProjectItem = new JMenuItem(MenuConsts.openProject); openProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_openProject))); openProjectItem.addActionListener(menuHandler); menu.add(openProjectItem); saveProjectItem = new JMenuItem(MenuConsts.saveProhect); saveProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_saveProject))); saveProjectItem.addActionListener(menuHandler); menu.add(saveProjectItem); closeProjectItem = new JMenuItem(MenuConsts.closeProject); closeProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_closeProject))); closeProjectItem.addActionListener(menuHandler); menu.add(closeProjectItem); menu.add(new JSeparator()); JMenuItem exitItem = new JMenuItem(MenuConsts.exit); exitItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_exit))); exitItem.addActionListener(menuHandler); menu.add(exitItem); return menu; }
Example #25
Source File: WindowsRootPaneUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
void altPressed(KeyEvent ev) { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] path = msm.getSelectedPath(); if (path.length > 0 && ! (path[0] instanceof ComboPopup)) { msm.clearSelectedPath(); menuCanceledOnPress = true; ev.consume(); } else if(path.length > 0) { // We are in ComboBox menuCanceledOnPress = false; WindowsLookAndFeel.setMnemonicHidden(false); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); ev.consume(); } else { menuCanceledOnPress = false; WindowsLookAndFeel.setMnemonicHidden(false); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); JMenuBar mbar = root != null ? root.getJMenuBar() : null; if(mbar == null && winAncestor instanceof JFrame) { mbar = ((JFrame)winAncestor).getJMenuBar(); } JMenu menu = mbar != null ? mbar.getMenu(0) : null; if(menu != null) { ev.consume(); } } }
Example #26
Source File: MainFrame.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates the menu bar. * * @return the j menu bar */ private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu optionsMenu = new JMenu("Options"); JMenuItem showInheritedFeatsItem = new JMenuItem("Show Inherited Features"); optionsMenu.add(showInheritedFeatsItem); menuBar.add(optionsMenu); return menuBar; }
Example #27
Source File: MWPaneDisambiguationMenuCreator.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Add submenus for linking texts. * * @param wiki Wiki. * @param popup Popup menu. * @param page Page. * @param text Text. * @param element Element. * @param textPane Text pane. */ public void addLinkText( EnumWikipedia wiki, JPopupMenu popup, Page page, String text, Element element, JTextPane textPane) { List<String> templates = null; if (wiki != null) { templates = wiki.getConfiguration().getStringList( WPCConfigurationStringList.TEMPLATES_FOR_LINKING_TEXT); } if ((text != null) && (page != null) && Boolean.TRUE.equals(page.isDisambiguationPage()) && (templates != null) && (templates.size() > 0)) { if (templates.size() > 1) { JMenu submenu = new JMenu(GT._T("Link text")); for (String template : templates) { addItem( submenu, null, GT._T("Using {0}", "{{" + template + "}}"), true, new MarkLinkAction( page, element, createTextForTemplate(template, page.getTitle(), text), textPane, null)); } popup.add(submenu); } else { addItem( popup, null, GT._T("Link text"), true, new MarkLinkAction( page, element, createTextForTemplate(templates.get(0), page.getTitle(), text), textPane, null)); } } }
Example #28
Source File: GUIMenuHelper.java From mts with GNU General Public License v3.0 | 5 votes |
private JMenu createJMenuHelp(ActionListener actionListener) { JMenu jMenu = new JMenu("Help"); jMenu.add(createJMenuItem(actionListener, "Documentation", HELP_DOCUMENTATION)); jMenu.add(createJMenuItem(actionListener, "XML Grammar", XML_GRAMMAR)); jMenu.add(new javax.swing.JSeparator()); jMenu.add(createJMenuItem(actionListener, "Web Site", HELP_WEBSITE)); jMenu.add(createJMenuItem(actionListener, "Source Forge", SOURCE_FORGE)); jMenu.add(new javax.swing.JSeparator()); jMenu.add(createJMenuItem(actionListener, "About", HELP_ABOUT)); return jMenu; }
Example #29
Source File: bug8071705.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void runActualTest(GraphicsDevice device, CountDownLatch latch, JFrame frame, boolean [] result) { Rectangle screenBounds = setLocation(frame, device); JMenu menu = frame.getJMenuBar().getMenu(0); menu.doClick(); Point location = menu.getLocationOnScreen(); JPopupMenu pm = menu.getPopupMenu(); Dimension pmSize = pm.getSize(); int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY"); int height = location.y + yOffset + pmSize.height + menu.getHeight(); int available = screenBounds.y + screenBounds.height - height; if (available > 0) { Point origin = pm.getLocationOnScreen(); if (origin.y < location.y) { // growing upward, wrong! result[0] = false; } else { // growing downward, ok! result[0] = true; } } else { // there is no space, growing upward would be ok, so we pass result[0] = true; } }
Example #30
Source File: bug8071705.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void runActualTest(GraphicsDevice device, CountDownLatch latch, JFrame frame, boolean [] result) { Rectangle screenBounds = setLocation(frame, device); JMenu menu = frame.getJMenuBar().getMenu(0); menu.doClick(); Point location = menu.getLocationOnScreen(); JPopupMenu pm = menu.getPopupMenu(); Dimension pmSize = pm.getSize(); int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY"); int height = location.y + yOffset + pmSize.height + menu.getHeight(); int available = screenBounds.y + screenBounds.height - height; if (available > 0) { Point origin = pm.getLocationOnScreen(); if (origin.y < location.y) { // growing upward, wrong! result[0] = false; } else { // growing downward, ok! result[0] = true; } } else { // there is no space, growing upward would be ok, so we pass result[0] = true; } }