List of usage examples for javax.swing JMenuBar add
public JMenu add(JMenu c)
From source file:savant.plugin.builtin.SavantFileRepositoryBrowser.java
private SavantFileRepositoryBrowser(Window parent) { super(parent, "Public Savant File Repository Browser", Dialog.ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); setResizable(true);/*from w ww. ja va2s.c o m*/ setLayout(new BorderLayout()); add(getCenterPanel(getDownloadTreeRows()), BorderLayout.CENTER); JMenuBar bottombar = new JMenuBar(); bottombar.setAlignmentX(RIGHT_ALIGNMENT); bottombar.add(Box.createHorizontalGlue()); JButton openbutt = new JButton("Load Track"); openbutt.putClientProperty("JButton.buttonType", "default"); openbutt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actOnSelectedItem(false); } }); bottombar.add(openbutt); JButton cancelButton = new JButton("Cancel"); cancelButton.putClientProperty("JButton.buttonType", "default"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeDialog(); } }); bottombar.add(cancelButton); add(bottombar, BorderLayout.SOUTH); setPreferredSize(new Dimension(800, 500)); pack(); setLocationRelativeTo(parent); }
From source file:savant.view.swing.BookmarkSheet.java
public BookmarkSheet(Container c) { // set the layout of the data sheet c.setLayout(new BorderLayout()); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); /**/* w ww.j a va 2 s . c om*/ * Create a toolbar. */ JMenuBar toolbar = new JMenuBar(); toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); c.add(toolbar, BorderLayout.NORTH); JButton previousButton = new JButton(); previousButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UP)); previousButton.setToolTipText("Go to previous bookmark [ Ctrl+( ]"); previousButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); previousButton.putClientProperty("JButton.segmentPosition", "first"); previousButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToPreviousBookmark(); } }); toolbar.add(previousButton); JButton nextButton = new JButton(); nextButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.DOWN)); nextButton.setToolTipText("Go to next bookmark [ Ctrl+) ]"); nextButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); nextButton.putClientProperty("JButton.segmentPosition", "last"); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToNextBookmark(); } }); toolbar.add(nextButton); JButton goButton = new JButton("Go"); goButton.setToolTipText("Go to selected bookmark"); goButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); goButton.putClientProperty("JButton.segmentPosition", "only"); goButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToSelectedBookmark(); } }); toolbar.add(goButton); toolbar.add(Box.createGlue()); addButton = new JButton(); addButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_ADD)); addButton.setToolTipText("Add bookmark for current range"); addButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); addButton.putClientProperty("JButton.segmentPosition", "first"); addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BookmarkController fc = BookmarkController.getInstance(); fc.addCurrentRangeToBookmarks(); } }); toolbar.add(addButton); JButton deleteButton = new JButton(); deleteButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_RM)); deleteButton.setToolTipText("Delete selected bookmarks"); deleteButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); deleteButton.putClientProperty("JButton.segmentPosition", "last"); deleteButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BookmarkController fc = BookmarkController.getInstance(); int[] selectedRows = table.getSelectedRows(); Arrays.sort(selectedRows); boolean delete = false; if (selectedRows.length > 0 && confirmDelete) { Object[] options = { "Yes", "No", "Yes, don't ask again" }; JLabel message = new JLabel( "Are you sure you want to delete " + selectedRows.length + " item(s)?"); message.setPreferredSize(new Dimension(300, 20)); int confirmDeleteDialog = JOptionPane.showOptionDialog(DialogUtils.getMainWindow(), message, "Confirm Delete", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (confirmDeleteDialog == 0) { delete = true; } else if (confirmDeleteDialog == 2) { delete = true; confirmDelete = false; } } else if (selectedRows.length > 0 && !confirmDelete) { delete = true; } if (delete) { for (int i = selectedRows.length - 1; i >= 0; i--) { fc.removeBookmark(selectedRows[i]); } } } }); toolbar.add(deleteButton); toolbar.add(Box.createGlue()); JButton loadButton = new JButton(); loadButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.OPEN)); loadButton.setToolTipText("Load bookmarks from file"); loadButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); loadButton.putClientProperty("JButton.segmentPosition", "first"); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadBookmarks(table); } }); toolbar.add(loadButton); JButton saveButton = new JButton(); saveButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SAVE)); saveButton.setToolTipText("Save bookmarks to file"); saveButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); saveButton.putClientProperty("JButton.segmentPosition", "last"); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveBookmarks(table); } }); toolbar.add(saveButton); // create a table (the most important component) table = new JTable(new BookmarksTableModel()); table.setAutoCreateRowSorter(true); table.setFillsViewportHeight(true); table.setShowGrid(true); table.setGridColor(Color.gray); //table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); // add the table and its header to the subpanel c.add(table.getTableHeader()); add(table); final JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); sp.setWheelScrollingEnabled(false); sp.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { sp.getVerticalScrollBar().setValue(sp.getVerticalScrollBar().getValue() + e.getUnitsToScroll() * 2); } }); c.add(sp); // add glue to fill the remaining space add(Box.createGlue()); }
From source file:savant.view.swing.Savant.java
private void initHiddenShortcuts() { JMenuBar hiddenBar = new JMenuBar(); hiddenBar.setSize(new Dimension(0, 0)); hiddenBar.setMaximumSize(new Dimension(0, 0)); hiddenBar.setPreferredSize(new Dimension(0, 0)); JMenuItem hiddenBookmarkPrev = new JMenuItem(""); hiddenBookmarkPrev.setAccelerator(//from ww w .j a va2 s. c om javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_9, MiscUtils.MENU_MASK)); hiddenBookmarkPrev.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { if (favoriteSheet != null) { favoriteSheet.goToPreviousBookmark(); } } }); JMenuItem hiddenBookmarkNext = new JMenuItem(""); hiddenBookmarkNext.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, MiscUtils.MENU_MASK)); hiddenBookmarkNext.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { if (favoriteSheet != null) { favoriteSheet.goToNextBookmark(); } } }); hiddenBar.add(hiddenBookmarkPrev); hiddenBar.add(hiddenBookmarkNext); this.add(hiddenBar); }
From source file:simplesqlformatter.formatter.SQLFormatterEditor.java
private void createEditMenu(JMenuBar menuBar, JToolBar toolBar) { final JMenu menuEdit = new JMenu("Edit"); final GuiAction copy = new GuiAction("Copy All", "/icons/edit_copy.gif"); copy.setShortcutKey(KeyStroke.getKeyStroke("control C")); copy.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { copy();// w w w . j a v a 2s . co m } }); menuEdit.add(copy); final GuiAction paste = new GuiAction("Paste Over", "/icons/edit_paste.gif"); paste.setShortcutKey(KeyStroke.getKeyStroke("control shift V")); paste.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { clear(); paste(); } }); menuEdit.add(paste); final GuiAction copyAsJavaString = new GuiAction("Copy as Java String", "/icons/edit_copy.gif"); copyAsJavaString.setShortcutKey(KeyStroke.getKeyStroke("control J")); copyAsJavaString.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { copyAsJavaString(); } }); menuEdit.add(copyAsJavaString); menuEdit.addSeparator(); final GuiAction format = new GuiAction("Format", "/icons/edit_format.gif"); format.setShortcutKey(KeyStroke.getKeyStroke("control F")); format.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { format(); } }); menuEdit.add(format); toolBar.add(format); final GuiAction formatFromClipboard = new GuiAction("Format From Clipboard", "/icons/edit_format_from_clipboard.gif"); formatFromClipboard.setShortcutKey(KeyStroke.getKeyStroke("control shift F")); formatFromClipboard.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { formatFromClipboard(); } }); menuEdit.add(formatFromClipboard); toolBar.add(formatFromClipboard); menuBar.add(menuEdit); }
From source file:simplesqlformatter.formatter.SQLFormatterEditor.java
private void createFileMenu(JMenuBar menuBar, JToolBar toolBar) { final JMenu menuFile = new JMenu("File"); final GuiAction newFile = new GuiAction("New", "/icons/file_new.gif"); newFile.setShortcutKey(KeyStroke.getKeyStroke("control N")); newFile.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { clear();// w ww.j a v a 2s . c o m } }); menuFile.add(newFile); toolBar.add(newFile); final GuiAction openFile = new GuiAction("Open", "/icons/file_open.gif"); openFile.setShortcutKey(KeyStroke.getKeyStroke("control O")); openFile.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { openFile(); } }); menuFile.add(openFile); toolBar.add(openFile); final GuiAction saveFile = new GuiAction("Save", "/icons/file_save.gif"); saveFile.setShortcutKey(KeyStroke.getKeyStroke("control S")); saveFile.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { saveFile(); } }); menuFile.add(saveFile); toolBar.add(saveFile); menuFile.addSeparator(); toolBar.addSeparator(); final ExitAction exit = new ExitAction(this, "Exit"); exit.setShortcutKey(KeyStroke.getKeyStroke("control Q")); menuFile.add(exit); menuBar.add(menuFile); }
From source file:simplesqlformatter.formatter.SQLFormatterEditor.java
private void createHelpMenu(JMenuBar menuBar, JToolBar toolBar) { final JMenu menuHelp = new JMenu("Help"); final GuiAction about = new GuiAction("About", "/icons/help_about.gif"); about.setShortcutKey(KeyStroke.getKeyStroke("control H")); about.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionevent) { JOptionPane.showMessageDialog(SQLFormatterEditor.this, Version.about(), Version.getProductName(), JOptionPane.PLAIN_MESSAGE); }//from w w w .ja v a 2s .c o m }); menuHelp.add(about); menuBar.add(menuHelp); }
From source file:unikn.dbis.univis.explorer.VExplorer.java
License:asdf
private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); VMenu program = new VMenu(Constants.PROGRAM); VMenuItem schemaImport = new VMenuItem(Constants.SCHEMA_IMPORT, VIcons.SCHEMA_IMPORT); schemaImport.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); schemaImport.addActionListener(new ActionListener() { /**//from w w w. ja va 2 s .co m * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.addChoosableFileFilter(new FileFilter() { /** * Whether the given file is accepted by this filter. */ public boolean accept(File f) { return f.getName().endsWith(".vs.xml") || f.isDirectory(); } /** * The description of this filter. For example: "JPG and GIF Images" * * @see javax.swing.filechooser.FileView#getName */ public String getDescription() { return "UniVis Schema (*.vs.xml)"; } }); int option = fileChooser.showOpenDialog(VExplorer.this); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); new SchemaImport(file); refreshTree(); JOptionPane.showMessageDialog(VExplorer.this, "Schema Import erfolgreich beendet.", "Schema Import", JOptionPane.INFORMATION_MESSAGE); } } }); program.add(schemaImport); program.addSeparator(); VMenuItem exit = new VMenuItem(Constants.EXIT, VIcons.EXIT); exit.setAccelerator(KeyStroke.getKeyStroke('Q', Event.ALT_MASK)); exit.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { System.exit(0); } }); program.add(exit); VMenu lafMenu = new VMenu(Constants.LOOK_AND_FEEL); ButtonGroup lafGroup = new ButtonGroup(); for (final UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { JRadioButtonMenuItem lafMenuItem = new JRadioButtonMenuItem(laf.getName()); // Set the current Look And Feel as selected. if (UIManager.getLookAndFeel().getName().equals(laf.getName())) { lafMenuItem.setSelected(true); } lafMenuItem.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { updateLookAndFeel(laf.getClassName()); } }); lafGroup.add(lafMenuItem); lafMenu.add(lafMenuItem); } JMenu questionMark = new JMenu("?"); VMenuItem license = new VMenuItem(Constants.LICENSE); license.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { new LicenseDialog(VExplorer.this); } }); questionMark.add(license); final VMenuItem about = new VMenuItem(Constants.ABOUT, VIcons.INFORMATION); about.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { new AboutPanel(VExplorer.this); } }); questionMark.add(about); menuBar.add(program); menuBar.add(lafMenu); menuBar.add(questionMark); setJMenuBar(menuBar); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Creates the various menu options and attaches the mnemonics and * registers listeners./* w ww . j a v a 2 s . c om*/ */ private void loadMenu() { JMenuBar menubar; menubar = new JMenuBar(); setJMenuBar(menubar); menubar.add(fileMenu()); menubar.add(editMenu()); menubar.add(queryMenu()); menubar.add(configurationMenu()); menubar.add(helpMenu()); }
From source file:us.paulevans.basicxslt.BasicXSLTFrame.java
/** * Create the menubar.//from www. j av a 2s . co m * */ private void buildMenuBar() { // local declarations... JMenuBar menuBar; JMenu help, file, validation, view; // build the file menu and associated menu items... file = new JMenu(stringFactory.getString(LabelStringFactory.MF_FILE_MENU)); file.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_MENU)); resetForm = new JMenuItem(stringFactory.getString(LabelStringFactory.MF_FILE_RESET_FORM_MI)); resetForm.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_RESET_FORM_MI)); resetForm.addActionListener(this); file.add(resetForm); file.add(new JSeparator()); file.add(loadConfiguration = new JMenuItem( stringFactory.getString(LabelStringFactory.MF_FILE_LOAD_CONFIGURATION_MI))); loadConfiguration.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_LOAD_CONFIGURATION_MI)); file.add(saveConfiguration = new JMenuItem( stringFactory.getString(LabelStringFactory.MF_FILE_SAVE_CONFIGURATION_MI))); saveConfiguration.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_SAVE_CONFIGURATION_MI)); file.add(saveAsConfiguration = new JMenuItem( stringFactory.getString(LabelStringFactory.MF_FILE_SAVE_CONFIGURATION_AS_MI))); saveAsConfiguration .setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_SAVE_CONFIGURATION_AS_MI)); loadConfiguration.addActionListener(this); saveConfiguration.addActionListener(this); saveAsConfiguration.addActionListener(this); file.add(new JSeparator()); exit = new JMenuItem(stringFactory.getString(LabelStringFactory.MF_FILE_EXIT_MI)); exit.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_FILE_EXIT_MI)); exit.addActionListener(this); file.add(exit); // build the validation menu and associated menu items... validation = new JMenu(stringFactory.getString(LabelStringFactory.MF_VALIDATION_MENU)); validation.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VALIDATION_MENU)); validation.add(checkSaxWarning = new JCheckBoxMenuItem( stringFactory.getString(LabelStringFactory.MF_VALIDATION_CHECK_SAX_WARNINGS_MI))); checkSaxWarning .setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VALIDATION_CHECK_SAX_WARNINGS_MI)); validation.add(checkSaxError = new JCheckBoxMenuItem( stringFactory.getString(LabelStringFactory.MF_VALIDATION_CHECK_SAX_ERRORS_MI))); checkSaxError.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VALIDATION_CHECK_SAX_ERRORS_MI)); validation.add(checkSaxFatalError = new JCheckBoxMenuItem( stringFactory.getString(LabelStringFactory.MF_VALIDATION_CHECK_SAX_FATAL_MI))); checkSaxFatalError .setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VALIDATION_CHECK_SAX_FATAL_MI)); // build the view menu and associate menu items... view = new JMenu(stringFactory.getString(LabelStringFactory.MF_VIEW_MENU)); view.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VIEW_MENU)); view.add(transformTimings = new JMenuItem( stringFactory.getString(LabelStringFactory.MF_VIEW_LAST_TIMINGS_MI))); transformTimings.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_VIEW_LAST_TIMINGS_MI)); transformTimings.setEnabled(false); transformTimings.addActionListener(this); // build the help menu and associated menu items... help = new JMenu(stringFactory.getString(LabelStringFactory.MF_HELP_MENU)); help.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_HELP_MENU)); about = new JMenuItem(stringFactory.getString(LabelStringFactory.MF_HELP_ABOUT_MI)); about.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.MF_HELP_ABOUT_MI)); about.addActionListener(this); help.add(about); // build the menubar... menuBar = new JMenuBar(); menuBar.add(file); menuBar.add(validation); menuBar.add(view); menuBar.add(help); setJMenuBar(menuBar); }
From source file:us.paulevans.basicxslt.OutputFrame.java
/** * Builds the GUI menu bar.//from ww w . jav a 2 s . co m */ private void buildMenuBar() { JMenu file, view; JMenuBar menuBar; menuBar = new JMenuBar(); file = new JMenu(stringFactory.getString(LabelStringFactory.OF_FILE_MENU)); file.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.OF_FILE_MENU)); close = new JMenuItem(stringFactory.getString(LabelStringFactory.OF_FILE_CLOSE_MI)); close.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.OF_FILE_CLOSE_MI)); close.addActionListener(this); file.add(close); menuBar.add(file); if (xslRows != null) { view = new JMenu(stringFactory.getString(LabelStringFactory.OF_VIEW_MENU)); view.setMnemonic(stringFactory.getMnemonic(LabelStringFactory.OF_VIEW_MENU)); view.add(transformTimings = new JMenuItem( stringFactory.getString(LabelStringFactory.OF_VIEW_TRANSFORM_TIMINGS_DETAIL_MI))); transformTimings .setMnemonic(stringFactory.getMnemonic(LabelStringFactory.OF_VIEW_TRANSFORM_TIMINGS_DETAIL_MI)); transformTimings.addActionListener(this); menuBar.add(view); } setJMenuBar(menuBar); }