List of usage examples for javax.swing JMenuBar JMenuBar
public JMenuBar()
From source file:com.github.pemapmodder.pocketminegui.gui.server.ServerMainActivity.java
@Override protected void onStart() { lifetime = new ServerLifetime(this); // setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); setLayout(new GridBagLayout()); JMenuBar bar = new JMenuBar(); JMenu serverMenu = new JMenu("Server"); serverMenu.setMnemonic(KeyEvent.VK_S); JMenu playerMenu = new JMenu("Players"); playerMenu.setMnemonic(KeyEvent.VK_P); bar.add(serverMenu);/*from ww w . j a va2 s . com*/ bar.add(playerMenu); setJMenuBar(bar); startStopButton = new JButton("Start"); startStopButton.addActionListener(lifetime::listen); GridBagConstraints constr = new GridBagConstraints(); constr.gridx = 0; constr.gridy = 0; constr.fill = GridBagConstraints.VERTICAL; constr.weighty = 0.02; constr.weightx = 0.1; add(startStopButton, constr); constr.gridx = 1; constr.gridy = 1; constr.fill = GridBagConstraints.BOTH; constr.weightx = 0.8; constr.weighty = 0.9; add(consolePanel = new ConsolePanel(this), constr); }
From source file:components.MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from w ww . j a v a 2s . c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }
From source file:ToolBarTest.java
public ToolBarFrame() { setTitle("ToolBarTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add a panel for color change panel = new JPanel(); add(panel, BorderLayout.CENTER); // set up actions Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE); Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED); Action exitAction = new AbstractAction("Exit", new ImageIcon("exit.gif")) { public void actionPerformed(ActionEvent event) { System.exit(0);/*w w w . j a v a 2s . co m*/ } }; exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit"); // populate tool bar JToolBar bar = new JToolBar(); bar.add(blueAction); bar.add(yellowAction); bar.add(redAction); bar.addSeparator(); bar.add(exitAction); add(bar, BorderLayout.NORTH); // populate menu JMenu menu = new JMenu("Color"); menu.add(yellowAction); menu.add(blueAction); menu.add(redAction); menu.add(exitAction); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:DOMTreeTest.java
public DOMTreeFrame() { setTitle("DOMTreeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();/*from w w w .j a v a 2 s .c om*/ } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); }
From source file:de.dakror.virtualhub.server.ServerFrame.java
public void init() { initFiles();//from w w w. j av a2s. c o m logArea = new JTextArea(); logArea.setWrapStyleWord(true); logArea.setEditable(false); logArea.setLineWrap(true); DefaultCaret caret = (DefaultCaret) logArea.getCaret(); caret.setSelectionVisible(false); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); wrap = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); setContentPane(wrap); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Aktionen"); menu.add(new JMenuItem( new AbstractAction("Protokoll leeren", new ImageIcon(getClass().getResource("/img/trash.png"))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { logArea.setText(""); log("Protokoll geleert."); } })); menu.add(logEnabled = new JCheckBoxMenuItem("Protokoll aktiviert", new ImageIcon(getClass().getResource("/img/log.png")), true)); menu.add(packetLogEnabled = new JCheckBoxMenuItem("Paketverkehr protokollieren", new ImageIcon(getClass().getResource("/img/traffic.png")), false)); menu.addSeparator(); menu.add(new JMenuItem(new AbstractAction("Backup-Einstellungen", new ImageIcon(getClass().getResource("/img/backup_edit.png"))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { BackupEditDialog.show(); } catch (JSONException e1) { e1.printStackTrace(); } } })); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:InternalFrameDemo.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); // Set up the lone menu. JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu);/*from w ww. j av a 2 s . c o m*/ // Set up the first menu item. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); // Set up the second menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; }
From source file:external.jung.demo.RoadEditorDemo.java
/** * a driver for this demo/*from w w w. j a va 2s . c o m*/ */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final RoadEditorDemo demo = new RoadEditorDemo(); JMenu menu = new JMenu("File"); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java
/** * A standalone demo charting load averages. *//*from w w w . j a va2s.co m*/ public JLoadChart() { super("JLoadChart"); jkstat = new NativeJKstat(); int maxage = 600000; String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT"); ts1 = new TimeSeries("1min " + lavetext); ts1.setMaximumItemAge(maxage); ts5 = new TimeSeries("5min " + lavetext); ts5.setMaximumItemAge(maxage); ts15 = new TimeSeries("15min " + lavetext); ts15.setMaximumItemAge(maxage); updateAccessory(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(ts1); dataset.addSeries(ts5); dataset.addSeries(ts15); JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"), KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false); XYPlot xyplot = chart.getXYPlot(); NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT")); loadaxis.setAutoRange(true); loadaxis.setAutoRangeIncludesZero(true); xyplot.setRangeAxis(loadaxis); DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME")); daxis.setAutoRange(true); daxis.setFixedAutoRange(maxage); xyplot.setDomainAxis(daxis); addWindowListener(new winExit()); setContentPane(new ChartPanel(chart)); JMenuBar jm = new JMenuBar(); JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X); exitItem.addActionListener(this); jme.add(exitItem); jm.add(jme); setJMenuBar(jm); pack(); setVisible(true); Timer timer = new Timer(5000, this); timer.start(); }
From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java
public MasterControlPanel(JFrame frame) { _frame = frame;//from w ww.j a va2 s. co m initWindowListener(frame); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnActions = new JMenu("Actions"); menuBar.add(mnActions); JMenu mnDebug = new JMenu("Debug"); mnActions.add(mnDebug); JMenuItem mntmAddPluginpanel = new JMenuItem("Request null PluginPanel"); mntmAddPluginpanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Requesting null PluginPanel"); // TODO } }); mnDebug.add(mntmAddPluginpanel); JMenu mnOptions = new JMenu("Options"); menuBar.add(mnOptions); _viewMenu = new JMenu("Views"); _viewMenu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent arg0) { } @Override public void menuDeselected(MenuEvent arg0) { } @Override public void menuSelected(MenuEvent arg0) { updateViewMenu(); } }); menuBar.add(_viewMenu); // INITIALIZE MANAGERS // TODO: maybe call this in the Runnable and fire an event when finished _eventBus = new SwingEventBus(); _eventBus.register(this); DeviceManager.init(_eventBus); _pluginManager = new PluginManager(_eventBus); _pluginManager.loadPlugins(); // create the status bar panel and shove it down the bottom of the frame statusPanel = new StatusBar(frame); _frame.getContentPane().add(statusPanel, BorderLayout.SOUTH); _dockController = new CControl(frame); _frame.getContentPane().add(_dockController.getContentArea(), BorderLayout.CENTER); _panelFactory = new PluginPanelDockableFactory(_pluginManager); _dockController.addMultipleDockableFactory(PluginPanelDockableFactory.ID, _panelFactory); _dockController.createWorkingArea("root"); updateViewMenu(); EventQueue.invokeLater(new Runnable() { @Override public void run() { DeviceManager.start(null); } }); _runOnClose.add(new Runnable() { public void run() { _dockController.destroy(); DeviceManager.stop(); DeviceManager.shutdown(); System.exit(0); } }); }
From source file:at.tuwien.ifs.commons.gui.controls.MultiOptionToggleButton.java
public MultiOptionToggleButton(final ImageIcon[] icons, final String[] buttonTexts, final String tooltip, final MultiOptionToggleListener listener) { super(icons[0]); this.setToolTipText(tooltip); this.addActionListener(new ActionListener() { @Override/* ww w .ja va 2s . c o m*/ public void actionPerformed(ActionEvent e) { menu.show(MultiOptionToggleButton.this, 0, MultiOptionToggleButton.this.getHeight()); // highlight current selection final Component[] components = menu.getComponents(); for (Component c : components) { c.setBackground(null); } menu.getComponent(selectedIndex).setBackground(Color.GRAY); } }); for (int i = 0; i < buttonTexts.length; i++) { JMenuItem jMenuItem = new JMenuItem(buttonTexts[i], icons[i]); jMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { listener.performAction(e.getActionCommand()); selectedIndex = ArrayUtils.indexOf(buttonTexts, e.getActionCommand()); setIcon(icons[selectedIndex]); } }); menu.add(jMenuItem); } JMenuBar menuBar = new JMenuBar(); menuBar.setBorderPainted(false); menuBar.add(menu); }