List of usage examples for javax.swing JMenuBar JMenuBar
public JMenuBar()
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Initialize the Frame./*w w w . j av a 2 s .co m*/ * * @param title the window title * @param statsMenu an optional menu listing available statistics */ protected void init(String title, JMenu statsMenu) { setTitle(title); setContentPane(new ChartPanel(kbc.getChart())); addWindowListener(new winExit()); JMenuBar jm = new JMenuBar(); jm.add(fileMenu()); if (!(jkstat instanceof SequencedJKstat)) { jm.add(sleepMenu()); } if (statsMenu != null) { jm.add(statsMenu); } setJMenuBar(jm); pack(); setVisible(true); }
From source file:commonline.query.gui.Frame.java
private void initializeMenu(boolean isMac) { JMenu file = new JMenu("File"); JMenuItem open = new JMenuItem(openAction); JMenuItem clear = new JMenuItem(clearDatabaseAction); JMenuItem exit = new JMenuItem(new ExitAction()); file.add(open);/*from ww w .j ava2s . c o m*/ file.addSeparator(); file.add(clear); if (!isMac) { file.addSeparator(); file.add(exit); } JMenu query = new JMenu("Query"); JMenuItem execute = new JMenuItem(executeScriptAction); JMenuItem stop = new JMenuItem(stopScriptAction); query.add(execute); query.add(stop); JMenuBar menuBar = new JMenuBar(); menuBar.add(file); menuBar.add(query); setJMenuBar(menuBar); }
From source file:XMLWriteTest.java
public XMLWriteFrame() { setTitle("XMLWriteTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); chooser = new JFileChooser(); // add component to frame comp = new RectangleComponent(); add(comp);/* ww w. ja v a 2 s . c o m*/ // set up menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem newItem = new JMenuItem("New"); menu.add(newItem); newItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { comp.newDrawing(); } }); JMenuItem saveItem = new JMenuItem("Save with DOM/XSLT"); menu.add(saveItem); saveItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { saveDocument(); } catch (Exception e) { JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString()); } } }); JMenuItem saveStAXItem = new JMenuItem("Save with StAX"); menu.add(saveStAXItem); saveStAXItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { saveStAX(); } catch (Exception e) { JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString()); } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); }
From source file:MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*w ww .j a va 2 s . c om*/ 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/1.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); return menuBar; }
From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java
private void createMenu() { JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Load") { private static final long serialVersionUID = 1L; @Override//www . j a va 2s . c o m public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(StraightLineCullingTestForm.this) == JFileChooser.APPROVE_OPTION) { try { loadFile(fc.getSelectedFile()); } catch (IOException ex) { } } } }); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:jmap2gml.ScriptGui.java
/** * Formats the window, initializes the JMap2Script object, and sets up all * the necessary events./*from w w w . j av a2 s . co m*/ */ public ScriptGui() { setTitle("jmap to gml script converter"); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setLayout(new GridBagLayout()); this.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent we) { } @Override public void windowClosing(WindowEvent we) { saveConfig(); } @Override public void windowClosed(WindowEvent we) { } @Override public void windowIconified(WindowEvent we) { } @Override public void windowDeiconified(WindowEvent we) { } @Override public void windowActivated(WindowEvent we) { } @Override public void windowDeactivated(WindowEvent we) { } }); GridBagConstraints c = new GridBagConstraints(); setResizable(true); setIconImage((new ImageIcon("spikeup.png")).getImage()); jta = new JTextArea(38, 30); loadConfig(); JScrollPane jsp = new JScrollPane(jta); jsp.setRowHeaderView(new TextLineNumber(jta)); jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jsp.setSize(jsp.getWidth(), 608); // menu bar JMenuBar menubar = new JMenuBar(); // file menu JMenu file = new JMenu("File"); // load button JMenuItem load = new JMenuItem("Load jmap"); load.addActionListener(ae -> { JFileChooser fileChooser = new JFileChooser(prevDirectory); fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap")); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); prevDirectory = selectedFile.getAbsolutePath(); jm2s = new ScriptFromJmap(selectedFile.getPath(), false); jta.setText(""); jta.append(jm2s.toString()); jta.setCaretPosition(0); writeFile.setEnabled(true); drawPanel.setItems(jta.getText().split("\n")); } }); // add load to file menu file.add(load); // button to save script to file writeFile = new JMenuItem("Write file"); writeFile.addActionListener(ae -> { if (jm2s != null) { PrintWriter out; try { File f = new File( jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml"); out = new PrintWriter(f); out.append(jm2s.toString()); out.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); writeFile.setEnabled(false); JMenuItem gmx = new JMenuItem("Export as gmx"); gmx.addActionListener(ae -> { String fn = String.format("%s.room.gmx", prevDirectory); JFileChooser fc = new JFileChooser(prevDirectory); fc.setSelectedFile(new File(fn)); fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx")); fc.showDialog(null, "Save"); File f = fc.getSelectedFile(); if (f != null) { try { GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f)); } catch (FileNotFoundException ex) { Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex); } } }); // add to file menu file.add(writeFile); file.add(gmx); // add file menu to the menubar menubar.add(file); // Edit menu // display menu JMenu display = new JMenu("Display"); JMenuItem update = new JMenuItem("Update"); update.addActionListener(ae -> { drawPanel.setItems(jta.getText().split("\n")); }); display.add(update); JMenuItem gridToggle = new JMenuItem("Toggle Grid"); gridToggle.addActionListener(ae -> { drawPanel.toggleGrid(); }); display.add(gridToggle); JMenuItem gridOptions = new JMenuItem("Modify Grid"); gridOptions.addActionListener(ae -> { drawPanel.modifyGrid(); }); display.add(gridOptions); menubar.add(display); // sets the menubar setJMenuBar(menubar); // add the text area to the window c.gridx = 0; c.gridy = 0; add(jsp, c); // initialize the preview panel drawPanel = new Preview(this); JScrollPane scrollPane = new JScrollPane(drawPanel); // add preview panel to the window c.gridx = 1; c.gridwidth = 2; add(scrollPane, c); pack(); setMinimumSize(this.getSize()); setLocationRelativeTo(null); setVisible(true); drawPanel.setItems(jta.getText().split("\n")); }
From source file:com.loy.MainFrame.java
@SuppressWarnings("rawtypes") public void init() { String src = "ee.png"; try {// w w w.ja v a 2 s .c o m ClassPathResource classPathResource = new ClassPathResource(src); image = ImageIO.read(classPathResource.getURL()); this.setIconImage(image); } catch (IOException e) { } menu = new JMenu("LOG CONSOLE"); this.jmenuBar = new JMenuBar(); this.jmenuBar.add(menu); panel = new JPanel(new BorderLayout()); this.add(panel); ClassPathResource classPathResource = new ClassPathResource("application.yml"); Yaml yaml = new Yaml(); Map result = null; try { result = (Map) yaml.load(classPathResource.getInputStream()); } catch (IOException e1) { e1.printStackTrace(); } String platformStr = result.get("platform").toString(); String version = result.get("version").toString(); String jvmOption = result.get("jvmOption").toString(); @SuppressWarnings("unchecked") List<String> projects = (List<String>) result.get("projects"); platform = Platform.valueOf(platformStr); final Runtime runtime = Runtime.getRuntime(); File pidsForder = new File("./pids"); if (!pidsForder.exists()) { pidsForder.mkdir(); } else { File[] files = pidsForder.listFiles(); if (files != null) { for (File f : files) { f.deleteOnExit(); String pidStr = f.getName(); try { Long pid = new Long(pidStr); if (Processes.isProcessRunning(platform, pid)) { if (Platform.Windows == platform) { Processes.tryKillProcess(null, platform, new NullProcessor(), pid); } else { Processes.killProcess(null, platform, new NullProcessor(), pid); } } } catch (Exception ex) { } } } } File currentForder = new File(""); String rootPath = currentForder.getAbsolutePath(); rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", ""); rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", ""); for (String value : projects) { String path = value; String[] values = value.split("/"); value = values[values.length - 1]; String appName = value; value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar"; JMenuItem menuItem = new JMenuItem(appName); JTextArea textArea = new JTextArea(); textArea.setVisible(true); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setAutoscrolls(true); JScrollPane scorll = new JScrollPane(textArea); this.textSreaMap.put(appName, scorll); EComposite ecomposite = new EComposite(); ecomposite.setCommand(value); ecomposite.setTextArea(textArea); composites.put(appName, ecomposite); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<JScrollPane> values = textSreaMap.values(); for (JScrollPane t : values) { t.setVisible(false); } String actions = e.getActionCommand(); JScrollPane textArea = textSreaMap.get(actions); if (textArea != null) { textArea.setVisible(true); panel.removeAll(); panel.add(textArea); panel.repaint(); panel.validate(); self.repaint(); self.validate(); } } }); menu.add(menuItem); } new Thread(new Runnable() { @Override public void run() { int size = composites.keySet().size(); int index = 1; for (String appName : composites.keySet()) { EComposite composite = composites.get(appName); try { Process process = runtime.exec( "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand()); Long pid = Processes.processId(process); pids.add(pid); File pidsFile = new File("./pids", pid.toString()); pidsFile.createNewFile(); new WriteLogThread(process.getInputStream(), composite.getTextArea()).start(); } catch (IOException e) { e.printStackTrace(); } synchronized (lock) { try { if (index < size) { lock.wait(); } else { index++; } } catch (InterruptedException e) { e.printStackTrace(); } } } } }).start(); }
From source file:J3dSwingFrame.java
/** * Construct the test frame with a menubar and 3D canvas *//*from w w w .j a v a2s . c om*/ public J3dSwingFrame() { super("Java3D Tester"); // Disable lightweight menus JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menubar = new JMenuBar(); // File menu JMenu file_menu = new JMenu("File"); menubar.add(file_menu); close_menu = new JMenuItem("Exit"); close_menu.addActionListener(this); file_menu.add(close_menu); setJMenuBar(menubar); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getBestConfiguration(template); canvas = new Canvas3D(config); // add the canvas to this frame. Since this is the only thing added to // the main frame we don't care about layout managers etc. getContentPane().add(canvas, "Center"); constructWorld(); setSize(600, 600); }
From source file:edu.harvard.mcz.imagecapture.BulkMediaFrame.java
private void init() { thisFrame = this; setTitle("BulkMedia Preparation"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 902, 174);// ww w. j ava 2 s . com JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic(KeyEvent.VK_F); menuBar.add(mnFile); JMenuItem mntmPrepareDirectory = new JMenuItem("Prepare Directory"); mntmPrepareDirectory.setMnemonic(KeyEvent.VK_D); mntmPrepareDirectory.addActionListener(new PrepareDirectoryAction()); mnFile.add(mntmPrepareDirectory); JMenuItem mntmNewMenuItem = new JMenuItem("Exit"); mntmNewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { done(); } }); JMenuItem mntmNewMenuItem_1 = new JMenuItem("Edit Properties"); mntmNewMenuItem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PropertiesEditor p = new PropertiesEditor(); p.pack(); p.setVisible(true); } }); mnFile.add(mntmNewMenuItem_1); mntmNewMenuItem.setMnemonic(KeyEvent.VK_X); mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); mnFile.add(mntmNewMenuItem); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0)); JPanel panel = new JPanel(); contentPane.add(panel, BorderLayout.CENTER); panel.setLayout(new GridLayout(3, 2, 0, 0)); JLabel lblBaseUri = new JLabel("Base URI (first part of path to images on the web)"); lblBaseUri.setHorizontalAlignment(SwingConstants.TRAILING); panel.add(lblBaseUri, "2, 2"); textField = new JTextField(); textField.setEditable(false); textField.setText(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASEURI)); panel.add(textField); textField.setColumns(10); JLabel lblNewLabel = new JLabel("Local Path To Base (local mount path that maps to base URI)"); lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING); panel.add(lblNewLabel); textField_1 = new JTextField(); textField_1.setEditable(false); textField_1.setText(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); panel.add(textField_1); textField_1.setColumns(10); JLabel lblBeforeExitingWait = new JLabel( "Before exiting wait for both the Done and Thumbnails Built messages."); panel.add(lblBeforeExitingWait); JLabel lblThumbnailGenerationIs = new JLabel("Thumbnail generation is not reported on the progress bar."); panel.add(lblThumbnailGenerationIs); progressBar = new JProgressBar(); progressBar.setStringPainted(false); contentPane.add(progressBar, BorderLayout.NORTH); JPanel panel_1 = new JPanel(); contentPane.add(panel_1, BorderLayout.SOUTH); JButton btnPrepareDirectory = new JButton("Run"); btnPrepareDirectory.setToolTipText("Select a directory and prepare a bulk media file for images therein."); panel_1.add(btnPrepareDirectory); btnPrepareDirectory.addActionListener(new PrepareDirectoryAction()); btnPrepareDirectory.setPreferredSize(new Dimension(80, 25)); JButton btnExit = new JButton("Exit"); btnExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { done(); } }); panel_1.add(btnExit); }
From source file:cz.nn.copytables.gui.CopyTablesGUI.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Rudolf Rada ResourceBundle bundle = ResourceBundle.getBundle("locale"); menuBar = new JMenuBar(); menuFile = new JMenu(); menuItemOpenFile = new JMenuItem(); menuItemCloseFile = new JMenuItem(); menuItemConfig = new JMenuItem(); menuHelp = new JMenu(); menuItemHelp = new JMenuItem(); menuItemAbout = new JMenuItem(); CellConstraints cc = new CellConstraints(); //======== this ======== setBackground(new Color(204, 255, 204)); // JFormDesigner evaluation mark setBorder(/*ww w . j av a 2 s. co m*/ new javax.swing.border.CompoundBorder( new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0), "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent e) { if ("border".equals(e.getPropertyName())) throw new RuntimeException(); } }); setLayout(new FormLayout("default", "default, $lgap, default")); //======== menuBar ======== { //======== menuFile ======== { menuFile.setText(bundle.getString("CopyTablesGUI.menuFile.text")); //---- menuItemOpenFile ---- menuItemOpenFile.setText(bundle.getString("CopyTablesGUI.menuItemOpenFile.text")); menuItemOpenFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuItem2ActionPerformed(e); } }); menuFile.add(menuItemOpenFile); //---- menuItemCloseFile ---- menuItemCloseFile.setText(bundle.getString("CopyTablesGUI.menuItemCloseFile.text")); menuItemCloseFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuItem3ActionPerformed(e); } }); menuFile.add(menuItemCloseFile); //---- menuItemConfig ---- menuItemConfig.setText(bundle.getString("CopyTablesGUI.menuItemConfig.text")); menuItemConfig.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuItem4ActionPerformed(e); } }); menuFile.add(menuItemConfig); } menuBar.add(menuFile); //======== menuHelp ======== { menuHelp.setText(bundle.getString("CopyTablesGUI.menuHelp.text")); //---- menuItemHelp ---- menuItemHelp.setText(bundle.getString("CopyTablesGUI.menuItemHelp.text")); menuItemHelp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuItemHelpActionPerformed(e); } }); menuHelp.add(menuItemHelp); //---- menuItemAbout ---- menuItemAbout.setText(bundle.getString("CopyTablesGUI.menuItemAbout.text")); menuItemAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { menuItemAboutActionPerformed(e); } }); menuHelp.add(menuItemAbout); } menuBar.add(menuHelp); } add(menuBar, cc.xy(1, 1)); // JFormDesigner - End of component initialization //GEN-END:initComponents }