List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates file menu with save/exit options * * @return file menu// w w w . ja v a 2 s . com */ private JMenu createFileMenu() { JMenu menu = new JMenu("File"); // file menu JMenuItem item = new JMenuItem("Exit"); item.addActionListener(e -> System.exit(0)); menu.add(item); return menu; }
From source file:TextComponentDemo.java
protected JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); //Undo and redo are actions of our own creation. undoAction = new UndoAction(); menu.add(undoAction); redoAction = new RedoAction(); menu.add(redoAction);//from w ww. ja va 2 s .c o m menu.addSeparator(); //These actions come from the default editor kit. //Get the ones we want and stick them in the menu. menu.add(getActionByName(DefaultEditorKit.cutAction)); menu.add(getActionByName(DefaultEditorKit.copyAction)); menu.add(getActionByName(DefaultEditorKit.pasteAction)); menu.addSeparator(); menu.add(getActionByName(DefaultEditorKit.selectAllAction)); return menu; }
From source file:qmod.generator.MainWindow.java
@SuppressWarnings("unchecked") public MainWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Quick Mod Generator"); JLabel lblAuthors = new JLabel("Authors:"); authorField1 = new JTextField(); authorField1.setColumns(25);/*from www .j a v a2s. c om*/ JButton btnGenerateFile = new JButton("Generate File"); btnGenerateFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { writeFiles(); } }); authCombo1.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo1.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo1.setSelectedIndex(0); authCombo2.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo2.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo2.setSelectedIndex(0); authorField2 = new JTextField(); authorField2.setColumns(25); authCombo3.setFont(new Font("Dialog", Font.BOLD, 8)); authCombo3.setModel( (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" })); authCombo3.setSelectedIndex(0); authorField3 = new JTextField(); authorField3.setColumns(25); JLabel lblCategories = new JLabel("Categories:"); categoriesField = new JTextField(); categoriesField.setColumns(10); JLabel lblDescription = new JLabel("Description:"); JEditorPane descriptionField = new JEditorPane(); JLabel lblLicense = new JLabel("License:"); licenseField = new JTextField(); licenseField.setColumns(10); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createParallelGroup(Alignment.TRAILING).addComponent(btnGenerateFile) .addGroup(groupLayout.createSequentialGroup().addComponent(lblAuthors) .addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout .createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup() .addComponent( authCombo2, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) .addGap(6).addComponent(authorField2, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup().addComponent( authCombo1, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE).addPreferredGap( ComponentPlacement.RELATED) .addComponent( authorField1, GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)) .addGroup(groupLayout.createSequentialGroup() .addComponent(authCombo3, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) .addGap(6).addGroup(groupLayout.createParallelGroup( Alignment.LEADING).addComponent( descriptionField) .addGroup(groupLayout .createParallelGroup( Alignment.LEADING, false) .addComponent(categoriesField) .addComponent( authorField3, GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)) .addGroup(groupLayout .createSequentialGroup() .addComponent(licenseField, GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE) .addPreferredGap( ComponentPlacement.RELATED))))))) .addComponent(lblCategories).addComponent(lblDescription)) .addGap(84)) .addGroup(groupLayout.createSequentialGroup().addComponent(lblLicense) .addContainerGap(377, Short.MAX_VALUE))))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout .createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblAuthors) .addComponent(authorField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(authCombo1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(authCombo2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(authCombo3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblCategories) .addComponent(categoriesField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblDescription) .addComponent(descriptionField, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addGap(9).addComponent(lblLicense)) .addGroup(groupLayout.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED) .addComponent(licenseField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addPreferredGap(ComponentPlacement.RELATED, 322, Short.MAX_VALUE).addComponent(btnGenerateFile) .addContainerGap())); getContentPane().setLayout(groupLayout); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); menuBar.add(mnFile); JMenuItem mntmNew = new JMenuItem("New"); mntmNew.setMnemonic(KeyEvent.VK_N); mnFile.add(mntmNew); JMenuItem mntmOpen = new JMenuItem("Open"); mnFile.add(mntmOpen); JMenuItem mntmSave = new JMenuItem("Save"); mnFile.add(mntmSave); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mntmExit.setMnemonic(KeyEvent.VK_X); mnFile.add(mntmExit); }
From source file:daylightchart.gui.DaylightChartGui.java
private void createOptionsMenu(final JMenuBar menuBar, final JToolBar toolBar) { final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.Options")); //$NON-NLS-1$ menu.setMnemonic('O'); final GuiAction options = new OptionsAction(this); menu.add(options); final GuiAction chartOptions = new ChartOptionsAction(this); menu.add(chartOptions);//from w w w .ja v a 2s .c o m final GuiAction resetAll = new ResetAllAction(this); menu.add(resetAll); menu.addSeparator(); final JCheckBoxMenuItem slimUiMenuItem = new JCheckBoxMenuItem( Messages.getString("DaylightChartGui.Menu.Options.SlimUi")); //$NON-NLS-1$ slimUiMenuItem.setState(isSlimUi()); slimUiMenuItem.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { final boolean slimUi = e.getStateChange() == ItemEvent.SELECTED; final Options options = UserPreferences.optionsFile().getData(); options.setSlimUi(slimUi); UserPreferences.optionsFile().save(options); ResetAllAction.restart(DaylightChartGui.this, slimUi); } }); menu.add(slimUiMenuItem); menuBar.add(menu); toolBar.add(options); toolBar.add(chartOptions); toolBar.addSeparator(); }
From source file:TextComponentDemo.java
protected JMenu createStyleMenu() { JMenu menu = new JMenu("Style"); Action action = new StyledEditorKit.BoldAction(); action.putValue(Action.NAME, "Bold"); menu.add(action); action = new StyledEditorKit.ItalicAction(); action.putValue(Action.NAME, "Italic"); menu.add(action);/*from w ww. j a v a 2s .com*/ action = new StyledEditorKit.UnderlineAction(); action.putValue(Action.NAME, "Underline"); menu.add(action); menu.addSeparator(); menu.add(new StyledEditorKit.FontSizeAction("12", 12)); menu.add(new StyledEditorKit.FontSizeAction("14", 14)); menu.add(new StyledEditorKit.FontSizeAction("18", 18)); menu.addSeparator(); menu.add(new StyledEditorKit.FontFamilyAction("Serif", "Serif")); menu.add(new StyledEditorKit.FontFamilyAction("SansSerif", "SansSerif")); menu.addSeparator(); menu.add(new StyledEditorKit.ForegroundAction("Red", Color.red)); menu.add(new StyledEditorKit.ForegroundAction("Green", Color.green)); menu.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue)); menu.add(new StyledEditorKit.ForegroundAction("Black", Color.black)); return menu; }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates new help menu with help/about options * * @return help menu/*from ww w .jav a2 s .c om*/ */ private JMenu createHelpMenu() { JMenu menu = new JMenu("Help"); // help menu JMenuItem item = new JMenuItem("Help"); // help menu -> help item.addActionListener(e -> showHelpDialogOrFail()); menu.add(item); item = new JMenuItem("About"); // help menu -> about item.addActionListener(e -> showAboutDialogOrFail()); menu.add(item); return menu; }
From source file:net.sf.clichart.main.ChartFrame.java
private void createMenu() { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w ww .j av a 2 s . com*/ JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem saveItem = new JMenuItem("Save as...", KeyEvent.VK_S); saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { saveChart(); } }); fileMenu.add(saveItem); JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_Q); exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.addSeparator(); fileMenu.add(exitItem); }
From source file:DialogTest.java
public DialogFrame() { setTitle("DialogTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // construct a File menu JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);//from w ww. j av a 2 s . co m JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); // add About and Exit menu items // The About item shows the About dialog JMenuItem aboutItem = new JMenuItem("About"); aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (dialog == null) // first time dialog = new AboutDialog(DialogFrame.this); dialog.setVisible(true); // pop up dialog } }); fileMenu.add(aboutItem); // The Exit item exits the program JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); }
From source file:com.ivli.roim.controls.ChartControl.java
@Override public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e) && (iMarker instanceof DomainMarker || iSeries instanceof XYSeries)) { JPopupMenu mnu = new JPopupMenu( java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MNU_MARKER_OPERATIONS")); if (iSeries instanceof XYSeries) { mnu.add(MENUS.ADD.makeItem(this)); mnu.add(MENUS.EXPORT_CSV.makeItem(this)); mnu.add(MENUS.DELETE_ALL.makeItem(this)); } else if (iMarker instanceof DomainMarker) { JMenu mi1 = new JMenu(MENUS.MOVE_TO_MIN.iText); mi1.add(MENUS.MOVE_TO_MIN.makeItem(this)); // mi1.add(MENUS.MOVE_TO_MIN_LEFT.makeItem(this)); // mi1.add(MENUS.MOVE_TO_MIN_RIGHT.makeItem(this)); mnu.add(mi1);//from w w w . j a va 2s . co m JMenu mi2 = new JMenu(MENUS.MOVE_TO_MAX.iText); mi2.add(MENUS.MOVE_TO_MAX.makeItem(this)); // mi2.add(MENUS.MOVE_TO_MAX_LEFT.makeItem(this)); // mi2.add(MENUS.MOVE_TO_MAX_RIGHT.makeItem(this)); mnu.add(mi2); mnu.add(MENUS.MOVE_TO_MEDIAN.makeItem(this)); //if(!getDomainMarkersForSeries()){ JMenu mi3 = new JMenu( java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MARKER_COMMAND.FIT")); mi3.add(MENUS.FIT_LEFT.makeItem(this)); mi3.add(MENUS.FIT_RIGHT.makeItem(this)); mnu.add(mi3); //} mnu.add(MENUS.DELETE.makeItem(this)); } mnu.show(this, e.getX(), e.getY()); } else { super.mouseReleased(e); dropSelection(); } }
From source file:SwingTest.java
public JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = null; menu = new JMenu("File"); menu.add(createMenuItem("File", "Save Image", this)); menu.add(createMenuItem("File", "Exit", this)); menuBar.add(menu);/*from w w w . j a va2s. com*/ menu = new JMenu("View"); menu.add(createMenuItem("View", "Cube", this)); menu.add(createMenuItem("View", "Sphere", this)); menuBar.add(menu); menu = new JMenu("Rotate"); menu.add(createMenuItem("Rotate", "On", this)); menu.add(createMenuItem("Rotate", "Off", this)); menuBar.add(menu); return menuBar; }