List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem()
JMenuItem
with no set text or icon. From source file:Main.java
public static JMenuItem buildMenuItem(String text, String actioncmd, ActionListener al) { JMenuItem mi = new JMenuItem(); mi.setBackground(Color.lightGray); mi.setText(text);//from w ww. j av a 2 s . c o m mi.setActionCommand(actioncmd); mi.addActionListener(al); return mi; }
From source file:Main.java
/** * Creates a copy of this menu item, whose contents update automatically * whenever the original menu item changes. *//* www . j av a 2 s . c o m*/ public static JMenuItem cloneMenuItem(final JMenuItem item) { if (item == null) return null; JMenuItem jmi; if (item instanceof JMenu) { final JMenu menu = (JMenu) item; final JMenu jm = new JMenu(); final int count = menu.getItemCount(); for (int i = 0; i < count; i++) { final JMenuItem ijmi = cloneMenuItem(menu.getItem(i)); if (ijmi == null) jm.addSeparator(); else jm.add(ijmi); } jmi = jm; } else jmi = new JMenuItem(); final ActionListener[] l = item.getActionListeners(); for (int i = 0; i < l.length; i++) jmi.addActionListener(l[i]); jmi.setActionCommand(item.getActionCommand()); syncMenuItem(item, jmi); linkMenuItem(item, jmi); return jmi; }
From source file:cz.lidinsky.editor.Menu.java
protected JMenuItem loadMenuItem(Properties settings, String key) { try {//ww w . ja v a 2 s. c om String temp = settings.getProperty(key + "_menu_items"); JMenuItem menuItem; if (temp != null) { JMenu menu = new JMenu(); String menuItems[] = temp.split(" "); for (String item : menuItems) { if (item.equals("|")) { menu.add(new JSeparator()); } else { menu.add(loadMenuItem(settings, item)); } } menuItem = menu; } else { menuItem = new JMenuItem(); } // set the menu item label setLabel(menuItem, settings.getProperty(key + "_menu_label")); // action String actionKey = settings.getProperty(key + "_menu_action"); if (actionKey != null) { menuItem.setAction(Action.getAction(settings, actionKey)); } return menuItem; } catch (Exception e) { // TODO: throw new AssertionError(); } }
From source file:org.pgptool.gui.ui.keyslist.KeysListView.java
private void initMenuBar() { menuBar = new JMenuBar(); JMenu menuTs = new JMenu(Messages.get("term.actions")); menuTs.add(miImport = new JMenuItem()); menuTs.add(miCreate = new JMenuItem()); menuTs.addSeparator();/*www .ja va 2s.c om*/ menuTs.add(miExportPublicKeys = new JMenuItem()); menuTs.addSeparator(); menuTs.add(miClose = new JMenuItem()); menuBar.add(menuTs); }
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(/*from w w w .j a v a 2 s.c om*/ 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 }
From source file:de.javagl.jgltf.browser.MenuNodes.java
/** * Create a list of menu items (which may be JMenu instances) for the * given {@link MenuNode} instances. /*from w ww. j av a2 s .c o m*/ * * @param menuNodes The {@link MenuNode}s * @return The menus */ private static List<JMenuItem> createMenuItems(List<? extends MenuNode> menuNodes) { List<JMenuItem> menuItems = new ArrayList<JMenuItem>(); for (MenuNode menuNode : menuNodes) { if (menuNode.children != null) { JMenu menu = new JMenu(); menu.setText(menuNode.label); List<JMenuItem> childMenuItems = createMenuItems(menuNode.children); for (JMenuItem childMenuItem : childMenuItems) { menu.add(childMenuItem); } menuItems.add(menu); } else { if (menuNode.command == null) { logger.warning("Empty menu node - skipping"); continue; } JMenuItem menuItem = new JMenuItem(); String label = "<html>" + menuNode.label + " <font size=-2>(" + menuNode.command + ")</font>" + "</html>"; menuItem.setText(label); menuItem.setActionCommand(menuNode.command); menuItems.add(menuItem); } } return menuItems; }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionMappingTask.java
private void createPopupMenu() { menu = new JPopupMenu("Popup menu"); JMenuItem item;/*w w w . j ava 2 s .c o m*/ // item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.SHOW_HIDE_INFO_CONNECTION)); // item.setActionCommand(SHOW); // item.addActionListener(this); // menu.add(item); itemConfidence = new JMenuItem(); menu.add(itemConfidence); itemImplied = new JCheckBoxMenuItem(); menu.add(itemImplied); item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION)); item.setActionCommand(DELETE); item.addActionListener(this); menu.add(item); }
From source file:AltiConsole.AltiConsoleMainScreen.java
/** * Constructs main screen of the application. * /*w w w . j av a 2 s . c om*/ * @param title * the frame title. */ public AltiConsoleMainScreen(final String title) { super(title); trans = Application.getTranslator(); // //////// Menu code starts her ////////////// // File fileMenu = new JMenu(); fileMenu.setText(trans.get("AltiConsoleMainScreen.File")); // Load data loadDataMenuItem = new JMenuItem(); loadDataMenuItem.setText(trans.get("AltiConsoleMainScreen.RetrieveFlightData")); loadDataMenuItem.setActionCommand("RETRIEVE_FLIGHT"); loadDataMenuItem.addActionListener(this); eraseAllDataMenuItem = new JMenuItem(); eraseAllDataMenuItem.setText(trans.get("AltiConsoleMainScreen.EraseFlightData")); eraseAllDataMenuItem.setActionCommand("ERASE_FLIGHT"); eraseAllDataMenuItem.addActionListener(this); // Save as saveASMenuItem = new JMenuItem(); saveASMenuItem.setText(trans.get("AltiConsoleMainScreen.saveFlightData")); saveASMenuItem.setActionCommand("SAVE_FLIGHT"); saveASMenuItem.addActionListener(this); // Exit exitMenuItem = new JMenuItem(); exitMenuItem.setText(trans.get("AltiConsoleMainScreen.Exit")); exitMenuItem.setActionCommand("EXIT"); exitMenuItem.addActionListener(this); fileMenu.add(saveASMenuItem); fileMenu.add(loadDataMenuItem); fileMenu.add(eraseAllDataMenuItem); fileMenu.add(exitMenuItem); // Option menu optionMenu = new JMenu(trans.get("AltiConsoleMainScreen.Option")); preferencesMenuItem = new JMenuItem(trans.get("AltiConsoleMainScreen.Preferences")); preferencesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("pref\n"); Preferences.showPreferences(AltiConsoleMainScreen.this); //LicenseDialog.showPreferences(AltiConsoleMainScreen.this); System.out.println("change units\n"); String Units; System.out.println(UserPref.getAppUnits()); if (Utils.equals(UserPref.getAppUnits(), "Unit.Metrics")) Units = trans.get("Unit.Metrics"); else Units = trans.get("Unit.Imperial"); chart.getXYPlot().getRangeAxis() .setLabel(trans.get("AltiConsoleMainScreen.altitude") + " (" + Units + ")"); if (Serial.getConnected()) { RetrievingFlight(); } } }); optionMenu.add(preferencesMenuItem); // Configuration menu altiConfigMenu = new JMenu(trans.get("AltiConsoleMainScreen.ConfigAltimeter")); retrieveAltiConfigMenuItem = new JMenuItem(trans.get("AltiConsoleMainScreen.RetrieveAltiConfig")); retrieveAltiConfigMenuItem.setActionCommand("RETRIEVE_ALTI_CFG"); retrieveAltiConfigMenuItem.addActionListener(this); altiConfigMenu.add(retrieveAltiConfigMenuItem); uploadFirmwareMenuItem = new JMenuItem(trans.get("AltiConsoleMainScreen.UploadFirmware")); uploadFirmwareMenuItem.setActionCommand("UPLOAD_FIRMWARE"); uploadFirmwareMenuItem.addActionListener(this); altiConfigMenu.add(uploadFirmwareMenuItem); // Help helpMenu = new JMenu(trans.get("AltiConsoleMainScreen.Help")); jJMenuBar = new JMenuBar(); // Manual onLineHelpMenuItem = new JMenuItem(trans.get("AltiConsoleMainScreen.onLineHelp")); onLineHelpMenuItem.setActionCommand("ON_LINE_HELP"); onLineHelpMenuItem.addActionListener(this); // license licenseMenuItem = new JMenuItem(trans.get("AltiConsoleMainScreen.license")); licenseMenuItem.setActionCommand("LICENSE"); licenseMenuItem.addActionListener(this); // AboutScreen aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(trans.get("AltiConsoleMainScreen.About")); aboutMenuItem.setActionCommand("ABOUT"); aboutMenuItem.addActionListener(this); helpMenu.add(onLineHelpMenuItem); helpMenu.add(licenseMenuItem); helpMenu.add(aboutMenuItem); jJMenuBar.add(fileMenu); jJMenuBar.add(optionMenu); jJMenuBar.add(altiConfigMenu); jJMenuBar.add(helpMenu); this.setJMenuBar(jJMenuBar); // ///// end of Menu code // Button retrieveFlights = new JButton(); retrieveFlights.setText(trans.get("AltiConsoleMainScreen.RetrieveFlights")); retrieveFlights.setActionCommand("RETRIEVE_FLIGHT"); retrieveFlights.addActionListener(this); retrieveFlights.setToolTipText(trans.get("AltiConsoleMainScreen.ttipRetrieveFlight")); // combo serial rate String[] serialRateStrings = { "300", "1200", "2400", "4800", "9600", "14400", "19200", "28800", "38400", "57600", "115200" }; serialRatesLabel = new JLabel(trans.get("AltiConsoleMainScreen.comPortSpeed") + " "); serialRates = new JComboBox(); System.out.println(UserPref.getDefComSpeed() + "\n"); for (int i = 0; i < serialRateStrings.length; i++) { serialRates.addItem(serialRateStrings[i]); if (Utils.equals(UserPref.getDefComSpeed(), serialRateStrings[i])) { serialRates.setSelectedIndex(i); } } serialRates.setToolTipText(trans.get("AltiConsoleMainScreen.ttipChoosePortSpeed")); comPortsLabel = new JLabel(trans.get("AltiConsoleMainScreen.port") + " "); comPorts = new JComboBox(); comPorts.setActionCommand("comPorts"); comPorts.addActionListener(this); comPorts.setToolTipText(trans.get("AltiConsoleMainScreen.ttipChooseAltiport")); listData = new DefaultListModel(); flightList = new JXList(listData); flightList.addListSelectionListener(new ValueReporter()); JPanel TopPanelLeft = new JPanel(); TopPanelLeft.setLayout(new BorderLayout()); TopPanelLeft.add(comPortsLabel, BorderLayout.WEST); TopPanelLeft.add(comPorts, BorderLayout.EAST); JPanel TopPanelMiddle = new JPanel(); TopPanelMiddle.setLayout(new BorderLayout()); TopPanelMiddle.add(retrieveFlights, BorderLayout.WEST); JPanel TopPanelRight = new JPanel(); TopPanelRight.setLayout(new BorderLayout()); TopPanelRight.add(serialRatesLabel, BorderLayout.WEST); TopPanelRight.add(serialRates, BorderLayout.EAST); JPanel TopPanel = new JPanel(); TopPanel.setLayout(new BorderLayout()); TopPanel.add(TopPanelRight, BorderLayout.EAST); TopPanel.add(TopPanelMiddle, BorderLayout.CENTER); TopPanel.add(TopPanelLeft, BorderLayout.WEST); JPanel MiddlePanel = new JPanel(); MiddlePanel.setLayout(new BorderLayout()); MiddlePanel.add(TopPanel, BorderLayout.NORTH); MiddlePanel.add(flightList, BorderLayout.WEST); String Units; if (Utils.equals(UserPref.getAppUnits(), "Unit.Metrics")) Units = trans.get("Unit.Metrics"); else Units = trans.get("Unit.Imperial"); chart = ChartFactory.createXYLineChart(trans.get("AltiConsoleMainScreen.Title"), trans.get("AltiConsoleMainScreen.time"), trans.get("AltiConsoleMainScreen.altitude") + " (" + Units + ")", null); chart.setBackgroundPaint(Color.white); System.out.println(chart.getSubtitle(0)); this.plot = chart.getXYPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); final ValueAxis axis = this.plot.getDomainAxis(); axis.setAutoRange(true); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); MiddlePanel.add(chartPanel, BorderLayout.CENTER); JPanel InfoPanel = new JPanel(new MigLayout("fill")); InfoPanel.add(new JLabel(trans.get("AltiConsoleMainScreen.ApogeeAltitude")), "gapright para"); apogeeAltitudeLabel = new JLabel(); InfoPanel.add(apogeeAltitudeLabel, "growx"); InfoPanel.add(new JLabel(trans.get("AltiConsoleMainScreen.MainAltitude")), "gapright para"); mainAltitudeLabel = new JLabel(); InfoPanel.add(mainAltitudeLabel, "growx"); flightNbrLabel = new JLabel(); InfoPanel.add(new JLabel(trans.get("AltiConsoleMainScreen.NbrOfPoint")), "growx"); nbrPointLabel = new JLabel(); InfoPanel.add(nbrPointLabel, "wrap rel,growx"); txtLog = new JTextArea(5, 70); txtLog.setEditable(false); txtLog.setAutoscrolls(true); scrollPane = new JScrollPane(txtLog); scrollPane.setAutoscrolls(true); // BottomPanel.add(scrollPane, BorderLayout.WEST); InfoPanel.add(scrollPane, "span"); // MiddlePanel.add(BottomPanel, BorderLayout.SOUTH); MiddlePanel.add(InfoPanel, BorderLayout.SOUTH); setContentPane(MiddlePanel); try { try { Serial = new AltimeterSerial(this); Serial.searchForPorts(); } catch (UnsatisfiedLinkError e) { System.out.println("USB Library rxtxSerial.dll Not Found"); System.out.println("Exception:" + e.toString() + ":" + e.getMessage()); System.out.println(e.toString()); JOptionPane.showMessageDialog(null, "You must copy the appropriate rxtxSerial.dll \n " + "to your local 32 bit or 64 bitjava JRE installation\n\n" + " .../arduino-1.0.1-windows/arduino-1.0.1/rxtxSerial.dll\n" + "to\n C:/Program Files (x86)/Java/jre7/bin/rxtxSerial.dll\n" + "also right click Properties->Unblock", trans.get("AltiConsoleMainScreen.InstallationProblem"), JOptionPane.WARNING_MESSAGE); } } catch (NoClassDefFoundError e) { System.out.println("Missing RXTXcomm.jar in java installation"); System.out.println("Exception:" + e.toString() + ":" + e.getMessage()); System.out.println(e.toString()); JOptionPane.showMessageDialog(null, "You must copy RXTXcomm.jar from the Arduino software\n " + "to your local 32 bit java JRE installation\n\n" + " .../arduino-1.0.1-windows/arduino-1.0.1/lib/RXTXcomm.jar\n" + "to\n C:/Program Files (x86)/Java/jre7/lib/ext/RXTXcomm.jar\n" + "also right click Properties->Unblock", trans.get("AltiConsoleMainScreen.InstallationProblem"), JOptionPane.WARNING_MESSAGE); } }
From source file:com.sec.ose.osi.ui.frm.main.JMenuMain.java
private JMenuItem getJMenuItemResumeIdentificationThread() { if (jMenuItemResumeSendingIdentificationThread == null) { jMenuItemResumeSendingIdentificationThread = new JMenuItem(); jMenuItemResumeSendingIdentificationThread.setText("Resume Sending Identification Thread"); jMenuItemResumeSendingIdentificationThread.setEnabled(false); jMenuItemResumeSendingIdentificationThread.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { log.debug("jMenuItemResumeSendingIdentificationThread actionPerformed()"); mEventHandler.handle(EventHandler.MAN_TOOL_RESUME_IDENTIFICATION_THREAD); }//www . j av a2 s .c o m }); } return jMenuItemResumeSendingIdentificationThread; }
From source file:org.sbml.bargraph.MainWindow.java
/** * Creates the main application frame.// www . j av a 2 s.c o m * * @param file A file to read and graph upon start up. If null, nothing * is graphed initially. */ public MainWindow(File file) { Log.note("Creating main application window."); setPlatformProperties(); setBackground(new Color(255, 255, 255)); setMaximumSize(new Dimension(2000, 1000)); setMinimumSize(new Dimension(600, 400)); setTitle("SBML Bar Graph"); setSize(new Dimension(600, 400)); setPreferredSize(new Dimension(600, 400)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 550, 400); contentPane = new JPanel(); contentPane.setSize(new Dimension(600, 400)); contentPane.setPreferredSize(new Dimension(600, 400)); contentPane.setMinimumSize(new Dimension(600, 400)); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); fileNamePanel = new JPanel(); fileNamePanel.setPreferredSize(new Dimension(590, 20)); fileNamePanel.setMinimumSize(new Dimension(590, 20)); fileNamePanel.setLayout(new BorderLayout(0, 0)); contentPane.add(fileNamePanel, BorderLayout.NORTH); fileNameField = new JTextField(); fileNameField.setHorizontalAlignment(SwingConstants.CENTER); fileNameField.setText("No file selected"); fileNameField.setDisabledTextColor(Color.LIGHT_GRAY); fileNameField.setFont(new Font("Lucida Grande", Font.ITALIC, 11)); fileNameField.setBorder(null); fileNameField.setOpaque(true); fileNameField.setBackground(UIManager.getColor("Separator.foreground")); fileNameField.setEnabled(false); fileNameField.setSize(new Dimension(590, 0)); fileNameField.setPreferredSize(new Dimension(590, 28)); fileNameField.setMinimumSize(new Dimension(590, 28)); fileNameField.setColumns(10); fileNamePanel.add(fileNameField, BorderLayout.CENTER); // The bar graph panel. chartPanel = new ChartPanel(createModelBarGraph(), false); contentPane.add(chartPanel, BorderLayout.CENTER); updatePanelForSBMLFile(file); // Manual additions for File menu. fileMenu = new JMenu(); fileMenu.setText("File"); openFileMenuItem = new JMenuItem(); openFileMenuItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, shortcutKeyMask)); openFileMenuItem.setText("Open..."); openFileMenuItem.setToolTipText("Open file to be graphed"); openFileMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { openFileHandler(evt); } }); fileMenu.add(openFileMenuItem); menuBar = new javax.swing.JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); // Replace the default Java window icon with our own. // This only has an effect on non-Mac OS systems. URL iconImageURL = getClass().getResource(Config.RES_ICON_APP); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image img = toolkit.createImage(iconImageURL); setIconImage(img); Log.note("Finished constructing panel and menu bar"); }