List of usage examples for javax.swing JMenuBar JMenuBar
public JMenuBar()
From source file:ActionExampleSwing.java
public ActionExampleSwing() { super("ActionExample Swing"); setChannel(currentChannel); // enable/disable the Actions as appropriate channelLabel.setHorizontalAlignment(JLabel.CENTER); channelLabel.setFont(new Font("Serif", Font.PLAIN, 32)); getContentPane().add(channelLabel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16)); getContentPane().add(buttonPanel, BorderLayout.CENTER); buttonPanel.add(new JButton(upAction)); buttonPanel.add(new JButton(gotoFavoriteAction)); buttonPanel.add(new JButton(downAction)); buttonPanel.add(new JButton(setFavoriteAction)); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("Channel"); menu.add(new JMenuItem(upAction)); menu.add(new JMenuItem(downAction)); menu.addSeparator();//w w w .ja v a 2s . co m menu.add(new JMenuItem(gotoFavoriteAction)); menu.add(new JMenuItem(setFavoriteAction)); mb.add(menu); setJMenuBar(mb); }
From source file:com.apatar.ui.Actions.java
private void createMenubar() { menubar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.add(newPrj);/*from w w w . jav a 2 s.c om*/ fileMenu.add(open); fileMenu.addSeparator(); fileMenu.add(save); fileMenu.add(saveAs); fileMenu.addSeparator(); // fileMenu.add(publishToApatar);@@ // fileMenu.add(runScheduling);@@ // fileMenu.addSeparator();@@ fileMenu.add(run); // fileMenu.addSeparator(); // apon // fileMenu.add(newWebService);@@ // fileMenu.addSeparator();@@ // fileMenu.add(options);@@ // fileMenu.addSeparator();@@ fileMenu.add(exit); // JMenu viewMenu = new JMenu("View");//@@ // viewMenu.add(windowsLookAndFeel);//@@ // viewMenu.add(metalLookAndFeel); //@@ // viewMenu.add(motifLookAndFeel); //@@ // JMenu debugMenu = new JMenu("Debug");//@@ // debugMenu.add(debugOutput);//@@ // debugMenu.add(errorOutput);//@@ // JMenu communityMenu = new JMenu("Community");//@@ // communityMenu.add(catalogOfApatars);//@@ // communityMenu.add(demos);//@@ // communityMenu.add(forums);//@@ // communityMenu.add(wiki);//@@ /* * @@ JMenu helpMenu = new JMenu("Help"); helpMenu.add(about); * helpMenu.addSeparator(); helpMenu.add(featureRequest); * helpMenu.add(submitBug); helpMenu.add(tutorials); */ menubar.add(fileMenu); // menubar.add(viewMenu);//@@ // menubar.add(debugMenu);//@@ // menubar.add(communityMenu);//@@ // menubar.add(helpMenu);//@@ }
From source file:CutAndPasteDemo.java
public CutAndPasteDemo() { super("Cut And Paste Demonstration"); clipboard = getToolkit().getSystemClipboard(); GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 15); textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25); textArea2 = new JTextArea("<Paste text here>", 5, 25); textArea1.setFont(font);/* w w w . j a v a 2 s . c om*/ textArea2.setFont(font); JPanel jPanel = new JPanel(); JMenuBar jMenuBar = new JMenuBar(); JMenuItem cutItem = new JMenuItem("Cut"); JMenuItem pasteItem = new JMenuItem("Paste"); JMenu jMenu = new JMenu("Edit"); jMenu.add(cutItem); jMenu.add(pasteItem); cutItem.addActionListener(new CutActionListener()); pasteItem.addActionListener(new PasteActionListener()); jMenuBar.add(jMenu); jPanel.add(jMenuBar); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); jPanel.add(textArea1); jPanel.add(Box.createRigidArea(new Dimension(0, 10))); jPanel.add(textArea2); getContentPane().add(jPanel, BorderLayout.CENTER); }
From source file:components.TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); //Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);/*from w w w . j a v a 2 s .com*/ textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); //Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); //Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); //Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); //Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); //Set up the menu bar. actions = createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); //Add some key bindings. addBindings(); //Put the initial text into the text pane. initDocument(); textPane.setCaretPosition(0); //Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:net.sf.jclal.gui.view.components.chart.ExternalBasicChart.java
/** * * @param windowsTitleParam The title of the window. * @param chartTitleParam The title of the chart panel. * @param xTitleParam The X-axis label./*from w ww . ja v a 2s . c o m*/ */ public ExternalBasicChart(String windowsTitleParam, String chartTitleParam, String xTitleParam) { reportFrecuency = 1; menubar = new JMenuBar(); menubar.add(createMenu()); max = -1; windowsTitle = windowsTitleParam; chartTitle = chartTitleParam; xTitle = xTitleParam; queryNames = new ArrayList<String>(); evaluationsCollection = new ArrayList<List<AbstractEvaluation>>(); controlCurveColor = new HashMap<String, Color>(); set = new HashSet<Integer>(); setSeries = new HashSet<String>(); colors = new ArrayList<Color>(); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(640, 480)); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseWheelEnabled(true); slider = new JSlider(JSlider.HORIZONTAL); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setToolTipText("Changes the report frecuency"); slider.setSnapToTicks(true); slider.setMinimum(1); slider.setMinorTickSpacing(1); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(javax.swing.event.ChangeEvent evt) { reportFrecuency = ((JSlider) evt.getSource()).getValue(); slider.setToolTipText(String.valueOf(reportFrecuency)); jComboBoxItemStateChanged(); } }); comboBox = new JComboBox<String>(); comboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent evt) { jComboBoxItemStateChanged(); } }); content = new JPanel(new BorderLayout()); content.add(comboBox, BorderLayout.NORTH); content.add(chartPanel, BorderLayout.CENTER); content.add(slider, BorderLayout.SOUTH); setJMenuBar(menubar); setTitle(windowsTitle); setContentPane(this.content); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
From source file:dmh.kuebiko.view.NoteStackFrame.java
/** * Create the frame./* w w w.ja va 2 s . c om*/ */ public NoteStackFrame(NoteManager noteMngr) { this.noteMngr = noteMngr; // Setup the various actions for the frame. noteMngr.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { boolean stackChanged = (Boolean) arg; toggleUnsavedChangeIndicator(stackChanged); if (!stackChanged) { notePanel.getHuxleyUiManager().resetTextChanged(); } } }); ActionObserverUtil.registerEnMass(actionMngr, observable, new NewNoteAction(this), new OpenNoteAction(this), new DeleteNoteAction(this), new RenameNoteAction(this), new SaveStackAction(this)); // Build the menus. menuBar = new JMenuBar(); setJMenuBar(menuBar); fileMenu = new JMenu("File"); menuBar.add(fileMenu); newNoteMenuItem = new JMenuItem(actionMngr.getAction(NewNoteAction.class)); fileMenu.add(newNoteMenuItem); JMenuItem openNoteMenuItem = new JMenuItem(actionMngr.getAction(OpenNoteAction.class)); fileMenu.add(openNoteMenuItem); deleteNoteMenuItem = new JMenuItem(actionMngr.getAction(DeleteNoteAction.class)); fileMenu.add(deleteNoteMenuItem); renameNoteMenuItem = new JMenuItem(actionMngr.getAction(RenameNoteAction.class)); fileMenu.add(renameNoteMenuItem); fileMenu.addSeparator(); newStackMenuItem = new JMenuItem(actionMngr.getAction(NewStackAction.class)); fileMenu.add(newStackMenuItem); openStackMenuItem = new JMenuItem(actionMngr.getAction(OpenStackAction.class)); fileMenu.add(openStackMenuItem); fileMenu.addSeparator(); closeMenuItem = new JMenuItem("Close"); closeMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); closeMenuItem.setEnabled(false); fileMenu.add(closeMenuItem); closeAllMenuItem = new JMenuItem("Close All"); closeAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); closeAllMenuItem.setEnabled(false); fileMenu.add(closeAllMenuItem); fileMenu.addSeparator(); saveMenuItem = new JMenuItem(actionMngr.getAction(SaveStackAction.class)); fileMenu.add(saveMenuItem); saveAllMenuItem = new JMenuItem("Save All"); saveAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); saveAllMenuItem.setEnabled(false); fileMenu.add(saveAllMenuItem); editMenu = new JMenu("Edit"); menuBar.add(editMenu); undoMenuItem = new JMenuItem("Undo"); undoMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(undoMenuItem); redoMenuItem = new JMenuItem("Redo"); // FIXME mac-specific keyboard shortcut redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(redoMenuItem); editMenu.addSeparator(); cutMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CutAction.class)); cutMenuItem.setText("Cut"); cutMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(cutMenuItem); copyMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CopyAction.class)); copyMenuItem.setText("Copy"); copyMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(copyMenuItem); pasteMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.PasteAction.class)); pasteMenuItem.setText("Paste"); pasteMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(pasteMenuItem); textMenu = new JMenu("Text"); menuBar.add(textMenu); JMenu windowMenu = new JMenu("Window"); menuBar.add(windowMenu); initialize(); additionalSetup(); }
From source file:misc.ActionDemo.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;// ww w .ja v a2s . c o m JMenuBar menuBar; //Create the menu bar. menuBar = new JMenuBar(); //Create the first menu. JMenu mainMenu = new JMenu("Menu"); Action[] actions = { leftAction, middleAction, rightAction }; for (int i = 0; i < actions.length; i++) { menuItem = new JMenuItem(actions[i]); menuItem.setIcon(null); //arbitrarily chose not to use icon mainMenu.add(menuItem); } //Set up the menu bar. menuBar.add(mainMenu); menuBar.add(createAbleMenu()); return menuBar; }
From source file:de.peterspan.csv2db.AppWindow.java
private void initialize() { frame = new JFrame(); frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage()); AppWindow._frame = frame;/*from w w w . jav a 2 s . c om*/ frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (reallyExit() == JOptionPane.YES_OPTION) { SingleInstance.release(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } }); frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ frame.setLocationRelativeTo(null); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$ menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$ mntmExit.setIcon(Icons.IC_LOGOUT_SMALL); mntmExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev); } }); mnFile.add(mntmExit); JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$ menuBar.add(mnEdit); JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$ mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL); mntmOptions.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // new OptionsDialog(frame); } }); mnEdit.add(mntmOptions); JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$ menuBar.add(mnHelp); JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$ mntmAbout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { new AboutDialog(frame); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mnHelp.add(mntmAbout); createContent(); DialogUtil.getInstance().setMainFrame(frame); }
From source file:net.adamjak.thomas.graph.application.gui.ResultsWidnow.java
private JMenuBar createJMenuBar() { this.jMenuBar = new JMenuBar(); // Menu File/*from w w w . j ava2 s.c o m*/ JMenu jmFile = new JMenu("File"); JMenuItem jmiFileSaveResults = new JMenuItem("Save results"); jmiFileSaveResults.setAccelerator(GuiAccelerators.CTRL_S); jmiFileSaveResults.addActionListener(new AlJmiFileSaveResults()); jmFile.add(jmiFileSaveResults); //jmFile.addSeparator(); this.jMenuBar.add(jmFile); return this.jMenuBar; }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Builds the menus.// ww w . j a v a 2 s . c o m * * @return The created menu bar. Is not null. */ private JMenuBar buildMenuBar() { final JMenuBar menuBar = new JMenuBar(); //File Menu final String fileMenuLabel = LocalisationManager.INSTANCE.getText("gui.menu.file"); final JMenu menuFile = new JMenu(fileMenuLabel); menuBar.add(menuFile); menuFile.add(new JMenuItem(new LoadDataAction())); menuFile.add(new JMenuItem(new SaveDataAction())); menuFile.addSeparator(); menuFile.add(new JMenuItem(new ExitAction())); //Help Menu final String helpMenuString = LocalisationManager.INSTANCE.getText("gui.menu.help"); final JMenu menuHelp = new JMenu(helpMenuString); menuBar.add(Box.createHorizontalGlue()); menuBar.add(menuHelp); menuHelp.add(new JMenuItem(new AboutDialogAction())); return menuBar; }