List of usage examples for javax.swing JMenuItem setText
@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.") public void setText(String text)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Use TextAction"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextArea leftArea = new JTextArea(); final JTextArea rightArea = new JTextArea(); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftArea), new JScrollPane(rightArea)); splitPane.setDividerLocation(.5);//from w w w. j a v a 2s. co m JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menu = new JMenu("Options"); menuBar.add(menu); JMenuItem menuItem; Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction); menuItem = menu.add(readAction); menuItem.setText("Make read-only"); Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction); menuItem = menu.add(writeAction); menuItem.setText("Make writable"); menu.addSeparator(); Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction); menuItem = menu.add(cutAction); menuItem.setText("Cut"); Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction); menuItem = menu.add(copyAction); menuItem.setText("Copy"); Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction); menuItem = menu.add(pasteAction); menuItem.setText("Paste"); frame.add(splitPane, BorderLayout.CENTER); frame.setSize(400, 250); frame.setVisible(true); }
From source file:UseActions.java
public static void main(String args[]) { JFrame frame = new JFrame("Use TextAction"); Container contentPane = frame.getContentPane(); Dimension empty = new Dimension(0, 0); final JTextArea leftArea = new JTextArea(); JScrollPane leftScrollPane = new JScrollPane(leftArea); leftScrollPane.setPreferredSize(empty); final JTextArea rightArea = new JTextArea(); JScrollPane rightScrollPane = new JScrollPane(rightArea); rightScrollPane.setPreferredSize(empty); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar);//from w ww . j av a 2 s . co m JMenu menu = new JMenu("Options"); menuBar.add(menu); JMenuItem menuItem; Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction); menuItem = menu.add(readAction); menuItem.setText("Make read-only"); Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction); menuItem = menu.add(writeAction); menuItem.setText("Make writable"); menu.addSeparator(); Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction); menuItem = menu.add(cutAction); menuItem.setText("Cut"); Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction); menuItem = menu.add(copyAction); menuItem.setText("Copy"); Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction); menuItem = menu.add(pasteAction); menuItem.setText("Paste"); contentPane.add(splitPane, BorderLayout.CENTER); frame.setSize(400, 250); frame.setVisible(true); splitPane.setDividerLocation(.5); }
From source file:GUI.MainWindow.java
/** * @param args the command line arguments *//*from w w w. j av a 2s . co m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> // Create right click context menu for most Text Components final JPopupMenu copypaste = new JPopupMenu(); JMenuItem cut = new JMenuItem(new DefaultEditorKit.CutAction()); cut.setText("Cut"); copypaste.add(cut); JMenuItem copy = new JMenuItem(new DefaultEditorKit.CopyAction()); copy.setText("Copy"); copypaste.add(copy); JMenuItem paste = new JMenuItem(new DefaultEditorKit.PasteAction()); paste.setText("Paste"); copypaste.add(paste); // Taken from here. It succinctly added a right click context menu to every text component. // http://stackoverflow.com/questions/19424574/adding-a-context-menu-to-all-swing-text-components-in-application javax.swing.UIManager.addAuxiliaryLookAndFeel(new LookAndFeel() { private final UIDefaults defaults = new UIDefaults() { public javax.swing.plaf.ComponentUI getUI(JComponent c) { if (c instanceof javax.swing.text.JTextComponent) { if (c.getClientProperty(this) == null) { c.setComponentPopupMenu(copypaste); c.putClientProperty(this, Boolean.TRUE); } } return null; } }; @Override public UIDefaults getDefaults() { return defaults; } ; @Override public String getID() { return "TextContextMenu"; } @Override public String getName() { return getID(); } @Override public String getDescription() { return getID(); } @Override public boolean isNativeLookAndFeel() { return false; } @Override public boolean isSupportedLookAndFeel() { return true; } }); /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainWindow().setVisible(true); } }); }
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); mi.setActionCommand(actioncmd);// w w w. j av a 2 s.co m mi.addActionListener(al); return mi; }
From source file:net.java.sip.communicator.impl.osdependent.jdic.TrayMenuFactory.java
/** * Changes the tray menu item properties, like name, text and icon. * @param trayItem the tray menu item to change * @param name the new name of the item// www. ja va2 s . com * @param textID the new text identifier * @param iconID the new icon string identifier */ private static void changeTrayMenuItem(Object trayItem, String name, String textID, String iconID) { String text = Resources.getString(textID); if (trayItem instanceof JMenuItem) { JMenuItem jmenuItem = (JMenuItem) trayItem; jmenuItem.setName(name); jmenuItem.setText(text); jmenuItem.setIcon(Resources.getImage(iconID)); } else if (trayItem instanceof MenuItem) { MenuItem menuItem = (MenuItem) trayItem; menuItem.setName(name); menuItem.setLabel(text); } }
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 w w . j ava 2s. 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:Main.java
/** Brings the destination menu item into sync with the source item. */ protected static void syncMenuItem(final JMenuItem source, final JMenuItem dest) { final boolean enabled = source.isEnabled(); if (dest.isEnabled() != enabled) dest.setEnabled(enabled);//w ww. j a v a2 s. c o m final int mnemonic = source.getMnemonic(); if (dest.getMnemonic() != mnemonic) dest.setMnemonic(mnemonic); final String text = source.getText(); if (dest.getText() != text) dest.setText(text); final KeyStroke accel = source.getAccelerator(); if (dest.getAccelerator() != accel) dest.setAccelerator(accel); }
From source file:ec.nbdemetra.chainlinking.outlineview.ChainLinkingChart.java
private JMenu newExportMenu() { DemetraUI demetraUI = DemetraUI.getDefault(); JMenu rslt = new JMenu("Export image to"); rslt.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O)); JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel)); copy.setText("Clipboard..."); copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD)); JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel)); file.setText("File..."); file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O)); rslt.add(copy);/*from w w w .java 2 s . co m*/ rslt.add(file); return rslt; }
From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java
private JMenu newExportMenu() { DemetraUI demetraUI = DemetraUI.getDefault(); JMenu result = new JMenu("Export image to"); result.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O)); JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel)); copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD)); copy.setText("Clipboard"); JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel)); file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O)); file.setText("File..."); result.add(copy);//www . ja v a2 s. c o m result.add(file); return result; }
From source file:ec.ui.chart.RevisionChartPanel.java
private JMenu buildMenu() { am = new ActionMap(); am.put(COPY_ACTION, new CopyAction()); im = new InputMap(); KeyStrokes.putAll(im, KeyStrokes.COPY, COPY_ACTION); JMenu result = new JMenu(); JMenuItem item; item = new JMenuItem(am.get(COPY_ACTION)); item.setText("Copy All"); item.setAccelerator(KeyStrokes.COPY.get(0)); ExtAction.hideWhenDisabled(item);/*from w ww . j av a 2s .c o m*/ result.add(item); return result; }