List of usage examples for javax.swing JMenuBar add
public JMenu add(JMenu c)
From source file:net.sf.clichart.main.ChartFrame.java
private void createMenu() { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w ww.ja va2s. c om*/ 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:TopLevelTransferHandlerDemo.java
private JMenuBar createDummyMenuBar() { JMenuBar mb = new JMenuBar(); mb.add(createDummyMenu("File")); mb.add(createDummyMenu("Edit")); mb.add(createDummyMenu("Search")); mb.add(createDummyMenu("View")); mb.add(createDummyMenu("Tools")); mb.add(createDummyMenu("Help")); JMenu demo = new JMenu("Demo"); demo.setMnemonic(KeyEvent.VK_D); mb.add(demo);/*from w w w . ja va2s.c om*/ thItem = new JCheckBoxMenuItem("Use Top-Level TransferHandler"); thItem.setMnemonic(KeyEvent.VK_T); demo.add(thItem); nullItem = new JCheckBoxMenuItem("Remove TransferHandler from List and Text"); nullItem.setMnemonic(KeyEvent.VK_R); demo.add(nullItem); copyItem = new JCheckBoxMenuItem("Use COPY Action"); copyItem.setMnemonic(KeyEvent.VK_C); demo.add(copyItem); return mb; }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }/* ww w .j a va 2 s .c o m*/ // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:com.google.code.facebook.graph.sna.applet.RadialTreeLensDemo.java
/** * create an instance of a simple graph with controls to * demo the zoomand hyperbolic features. * /*from w ww. j av a2s. c o m*/ */ public RadialTreeLensDemo() { // create a simple graph for the demo // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree(); layout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); Dimension preferredSize = new Dimension(600, 600); final VisualizationModel<String, Integer> visualizationModel = new DefaultVisualizationModel<String, Integer>( radialLayout, preferredSize); vv = new VisualizationViewer<String, Integer>(visualizationModel, preferredSize); PickedState<String> ps = vv.getPickedVertexState(); PickedState<Integer> pes = vv.getPickedEdgeState(); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Integer>(pes, Color.black, Color.cyan)); vv.setBackground(Color.white); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); rings = new Rings(); vv.addPreRenderPaintable(rings); hyperbolicViewSupport = new ViewLensSupport<String, Integer>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel hyperControls = new JPanel(new GridLayout(3, 2)); hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens")); zoomControls.add(plus); zoomControls.add(minus); JPanel modeControls = new JPanel(new BorderLayout()); modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modeControls.add(graphMouse.getModeComboBox()); hyperControls.add(hyperView); controls.add(zoomControls); controls.add(hyperControls); controls.add(modeControls); content.add(controls, BorderLayout.SOUTH); }
From source file:eu.europeana.sip.gui.SipCreatorGUI.java
private JMenuBar createMenuBar() { JMenuBar bar = new JMenuBar(); bar.add(new ImportMenu(this, sipModel, new Runnable() { @Override/* w w w . j av a2s .c o m*/ public void run() { for (FileStore.DataSetStore dataSetStore : sipModel.getFileStore().getDataSetStores().values()) { dataSetListModel.setDataSetStore(dataSetStore); } } })); bar.add(new RepositoryMenu(this, sipModel)); bar.add(dataSetActions.createPrefixActivationMenu()); return bar; }
From source file:edu.uci.ics.jung.samples.RadialTreeLensDemo.java
/** * create an instance of a simple graph with controls to * demo the zoomand hyperbolic features. * // w ww .j a v a 2 s . c om */ @SuppressWarnings({ "unchecked", "rawtypes" }) public RadialTreeLensDemo() { // create a simple graph for the demo // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree(); layout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); Dimension preferredSize = new Dimension(600, 600); final VisualizationModel<String, Integer> visualizationModel = new DefaultVisualizationModel<String, Integer>( radialLayout, preferredSize); vv = new VisualizationViewer<String, Integer>(visualizationModel, preferredSize); PickedState<String> ps = vv.getPickedVertexState(); PickedState<Integer> pes = vv.getPickedEdgeState(); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Integer>(pes, Color.black, Color.cyan)); vv.setBackground(Color.white); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); rings = new Rings(); vv.addPreRenderPaintable(rings); hyperbolicViewSupport = new ViewLensSupport<String, Integer>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel hyperControls = new JPanel(new GridLayout(3, 2)); hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens")); zoomControls.add(plus); zoomControls.add(minus); JPanel modeControls = new JPanel(new BorderLayout()); modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modeControls.add(graphMouse.getModeComboBox()); hyperControls.add(hyperView); controls.add(zoomControls); controls.add(hyperControls); controls.add(modeControls); content.add(controls, BorderLayout.SOUTH); }
From source file:de.freese.base.swing.mac_os_x.MyApp.java
/** * *//*from www . jav a 2 s.c om*/ public void addMenus() { JMenu fileMenu = new JMenu("File"); JMenuBar mainMenuBar = new JMenuBar(); mainMenuBar.add(fileMenu = new JMenu("File")); fileMenu.add(this.openMI = new JMenuItem("Open...")); this.openMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MENU_MASK)); this.openMI.addActionListener(this); // Quit/prefs menu items are provided on Mac OS X; only add your own on other platforms if (!IS_OS_MAC_OSX) { fileMenu.addSeparator(); fileMenu.add(this.optionsMI = new JMenuItem("Options")); this.optionsMI.addActionListener(this); fileMenu.addSeparator(); fileMenu.add(this.quitMI = new JMenuItem("Quit")); this.quitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_MASK)); this.quitMI.addActionListener(this); } mainMenuBar.add(this.helpMenu = new JMenu("Help")); this.helpMenu.add(this.docsMI = new JMenuItem("Online Documentation")); this.helpMenu.addSeparator(); this.helpMenu.add(this.supportMI = new JMenuItem("Technical Support")); // About menu item is provided on Mac OS X; only add your own on other platforms if (!IS_OS_MAC_OSX) { this.helpMenu.addSeparator(); this.helpMenu.add(this.aboutMI = new JMenuItem("About OSXAdapter")); this.aboutMI.addActionListener(this); } setJMenuBar(mainMenuBar); }
From source file:edu.clemson.cs.nestbed.client.gui.MessageMonitorFrame.java
private JMenuBar buildMenuBar() { JMenuBar menuBar = new JMenuBar(); menuBar.add(buildFileMenu()); return menuBar; }
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); bar.add(playerMenu);//from ww w . j ava 2s .com 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:de.peterspan.csv2db.AppWindow.java
private void initialize() { frame = new JFrame(); frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage()); AppWindow._frame = frame;/*from ww w . j a v a2s . c o m*/ 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); }