Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

In this page you can find the example usage for javax.swing JMenu JMenu.

Prototype

public JMenu(Action a) 

Source Link

Document

Constructs a menu whose properties are taken from the Action supplied.

Usage

From source file:gui.ReEditingPopupGraphMousePlugin.java

@SuppressWarnings({ "unchecked", "serial" })
protected void handlePopup(MouseEvent e) {
    final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
    final Layout<V, E> layout = vv.getGraphLayout();
    final Graph<V, E> graph = layout.getGraph();
    final Point2D p = e.getPoint();
    final Point2D ivp = p;
    GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();

    if (pickSupport != null) {
        final V vertex = pickSupport.getVertex(layout, ivp.getX(), ivp.getY());
        final E edge = pickSupport.getEdge(layout, ivp.getX(), ivp.getY());
        final PickedState<V> pickedVertexState = vv.getPickedVertexState();
        final PickedState<E> pickedEdgeState = vv.getPickedEdgeState();

        if (vertex != null) {
            Set<V> picked = pickedVertexState.getPicked();
            if (picked.size() > 0) {
                if (graph instanceof UndirectedGraph == false) {
                    JMenu directedMenu = new JMenu("Create Directed Edge");
                    popup.add(directedMenu);
                    for (final V other : picked) {
                        directedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex, EdgeType.DIRECTED);
                                vv.repaint();
                            }/*from  ww w .  j  a v  a2s .  c o m*/
                        });
                    }
                }
                if (graph instanceof DirectedGraph == false) {
                    JMenu undirectedMenu = new JMenu("Create Undirected Edge");
                    popup.add(undirectedMenu);
                    for (final V other : picked) {
                        undirectedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex);
                                vv.repaint();
                            }
                        });
                    }
                }
            }
            popup.add(new AbstractAction("Delete TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    pickedVertexState.pick(vertex, false);
                    graph.removeVertex(vertex);
                    vv.repaint();
                }
            });
        } else if (edge != null) {
            popup.add(new AbstractAction("Delete Edge") {
                public void actionPerformed(ActionEvent e) {
                    pickedEdgeState.pick(edge, false);
                    graph.removeEdge(edge);
                    vv.repaint();
                }
            });
        } else {
            popup.add(new AbstractAction("Create TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    V newVertex = vertexFactory.create();
                    graph.addVertex(newVertex);
                    layout.setLocation(newVertex,
                            vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p));
                    vv.repaint();
                }
            });
        }
        if (popup.getComponentCount() > 0) {
            popup.show(vv, e.getX(), e.getY());
        }
    }
}

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);//from   www  .j  a  v  a  2 s .  co  m

    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:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

public DisplayAAS() {
    dbAuswahlAAS = JKabelS.getSpringContext().getBean(DBAuswahlAAS.class);

    setTitle("jKabel");

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(south = getSouth(), BorderLayout.SOUTH);

    //File menue//from  w w  w .  j a  v  a2  s. c  om
    JMenu menue = new JMenu("File");
    menue.add(edit);
    menue.add(search);

    menue.add(auchf);

    menue.addSeparator();
    menue.add(getjTypSortMenu());
    menue.add(getjTrommelSortMenu());
    menue.addSeparator();
    menue.add(exit);

    edit.addActionListener(this);
    search.addActionListener(this);
    exit.addActionListener(this);
    auchf.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setZeigeAlle(auchf.isSelected());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    //License and more
    JMenu lMenue = new JMenu("Hilfe");
    lMenue.add(help);
    lMenue.add(gpl);

    help.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new HelpAAS();
        }
    });
    gpl.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new GPLAAS();
        }
    });

    // und zusammenbauen
    menuBar.add(menue);
    menuBar.add(lMenue);
    menuBar.add(new Version());

    // Trommelsuchband
    JMenuItem sbt = new JMenuItem("Suchen nach Trommelnummer");
    menuBar.add(sbt);
    sbt.addActionListener(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class));
    JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class).setVisible(false);
    getContentPane().add(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class), BorderLayout.NORTH);

    setJMenuBar(menuBar);

    IDBWrapper db = dbAuswahlAAS.getDBWrapper();

    bearbeitenPanel = (JPanel) JKabelS.getSpringContext().getBean("bearbeitenPanel");

    if (db == null) {
        center.add(new JLabel("Es konnte keine Verbindung zur DB hergestellt werden."));
        center.add(new JLabel(
                "Wenn !!!sicher!!! ist das kein anderer auf der DB arbeitet die lock.lck Datei lschen"));
        DisplayAAS d = this;
        getContentPane().add(center, BorderLayout.CENTER);
    } else {
        setDb(db);
    }

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
}

From source file:PreferencesTest.java

public PreferencesFrame() {
    // get position, size, title from preferences

    Preferences root = Preferences.userRoot();
    final Preferences node = root.node("/com/horstmann/corejava");
    int left = node.getInt("left", 0);
    int top = node.getInt("top", 0);
    int width = node.getInt("width", DEFAULT_WIDTH);
    int height = node.getInt("height", DEFAULT_HEIGHT);
    setBounds(left, top, width, height);

    // if no title given, ask user

    String title = node.get("title", "");
    if (title.equals(""))
        title = JOptionPane.showInputDialog("Please supply a frame title:");
    if (title == null)
        title = "";
    setTitle(title);//  ww  w .  j a  v  a2s. co m

    // set up file chooser that shows XML files

    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // accept all files ending with .xml
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory();
        }

        public String getDescription() {
            return "XML files";
        }
    });

    // set up menus
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem exportItem = new JMenuItem("Export preferences");
    menu.add(exportItem);
    exportItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    OutputStream out = new FileOutputStream(chooser.getSelectedFile());
                    node.exportSubtree(out);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem importItem = new JMenuItem("Import preferences");
    menu.add(importItem);
    importItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    InputStream in = new FileInputStream(chooser.getSelectedFile());
                    Preferences.importPreferences(in);
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            node.putInt("left", getX());
            node.putInt("top", getY());
            node.putInt("width", getWidth());
            node.putInt("height", getHeight());
            node.put("title", getTitle());
            System.exit(0);
        }
    });
}

From source file:ShowComponent.java

/**
 * This static method queries the system to find out what Pluggable
 * Look-and-Feel (PLAF) implementations are available. Then it creates a
 * JMenu component that lists each of the implementations by name and allows
 * the user to select one of them using JRadioButtonMenuItem components.
 * When the user selects one, the selected menu item traverses the component
 * hierarchy and tells all components to use the new PLAF.
 *//*from   w w w  .ja  va2s.  com*/
public static JMenu createPlafMenu(final JFrame frame) {
    // Create the menu
    JMenu plafmenu = new JMenu("Look and Feel");

    // Create an object used for radio button mutual exclusion
    ButtonGroup radiogroup = new ButtonGroup();

    // Look up the available look and feels
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();

    // Loop through the plafs, and add a menu item for each one
    for (int i = 0; i < plafs.length; i++) {
        String plafName = plafs[i].getName();
        final String plafClassName = plafs[i].getClassName();

        // Create the menu item
        JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));

        // Tell the menu item what to do when it is selected
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    // Set the new look and feel
                    UIManager.setLookAndFeel(plafClassName);
                    // Tell each component to change its look-and-feel
                    SwingUtilities.updateComponentTreeUI(frame);
                    // Tell the frame to resize itself to the its
                    // children's new desired sizes
                    frame.pack();
                } catch (Exception ex) {
                    System.err.println(ex);
                }
            }

        });

        // Only allow one menu item to be selected at once
        radiogroup.add(item);
    }
    return plafmenu;
}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java

/**
 * Create the File... Menu./*  w  w  w .  ja  va2  s  .  c  o  m*/
 *
 * @return the File Menu
 */
protected JMenu fileMenu() {
    JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT"));
    jme.setMnemonic(KeyEvent.VK_F);

    saveItem = new JMenuItem(KstatResources.getString("FILE.SAVEAS.TEXT"), KeyEvent.VK_S);
    saveItem.addActionListener(this);
    jme.add(saveItem);
    jme.addSeparator();
    exitItem = new JMenuItem(KstatResources.getString("FILE.CLOSE.TEXT"), KeyEvent.VK_C);
    exitItem.addActionListener(this);
    jme.add(exitItem);
    return jme;
}

From source file:Main.java

protected JMenuBar createMenuBar() {
    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    menubar.add(file);/*from  w  w  w.  ja v  a2s  . c  o m*/
    menubar.add(edit);

    file.add(getOpenAction());
    file.add(getSaveAction());
    file.add(new ExitAction());
    edit.add(textComp.getActionMap().get(DefaultEditorKit.cutAction));
    edit.add(textComp.getActionMap().get(DefaultEditorKit.copyAction));
    edit.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction));
    edit.add(textComp.getActionMap().get(DefaultEditorKit.selectAllAction));
    return menubar;
}

From source file:MenuSelectionManagerDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*from  ww w .  ja  v  a  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("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);

    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:be.fedict.eid.tsl.tool.TslTool.java

private void initHelpMenu(JMenuBar menuBar) {
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(helpMenu);/*from w w w .  j a v a 2 s.  c o m*/

    addActionMenuItem("About", KeyEvent.VK_A, ABOUT_ACTION_COMMAND, helpMenu);
}

From source file:com.sshtools.appframework.api.ui.ActionBuilder.java

protected void rebuildMenuBar(Collection<AppAction> enabledActions) {
    menuBar.invalidate();//from  w  w  w.  j  a v a  2  s .  c o  m

    // Build the menu bar action list
    menuBar.removeAll();
    List<AppAction> menuBarActions = new ArrayList<AppAction>();
    for (AppAction action : enabledActions) {
        if (Boolean.TRUE.equals(action.getValue(AppAction.ON_MENUBAR))) {
            menuBarActions.add(action);
        }
    }
    log.debug("There are " + menuBarActions.size() + " on the menubar");

    // Build the menu bar
    List<ActionMenu> menus = new ArrayList<ActionMenu>(listActionMenus());
    Collections.sort(menus);
    Map<String, List<AppAction>> map = new HashMap<String, List<AppAction>>();
    for (AppAction z : menuBarActions) {
        String menuName = (String) z.getValue(AppAction.MENU_NAME);
        if (menuName == null) {
        } else {
            ;
            String m = (String) z.getValue(AppAction.MENU_NAME);
            ActionMenu menu = getActionMenu(menus.iterator(), m);
            if (menu != null) {
                List<AppAction> x = map.get(menu.getName());
                if (x == null) {
                    x = new ArrayList<AppAction>();
                    map.put(menu.getName(), x);
                }
                x.add(z);
            }
        }
    }

    // Create the menu components
    for (ActionMenu m : menus) {
        List<AppAction> x = map.get(m.getName());
        if (x != null) {
            Collections.sort(x, new MenuItemActionComparator());
            JMenu menu = new JMenu(m.getDisplayName());
            menu.setMnemonic(m.getWeight());
            Integer grp = null;
            for (AppAction a : x) {
                Integer g = (Integer) a.getValue(AppAction.MENU_ITEM_GROUP);
                if ((grp != null) && !g.equals(grp)) {
                    menu.addSeparator();
                }
                grp = g;
                if (a instanceof MenuAction) {
                    JMenu mnu = (JMenu) a.getValue(MenuAction.MENU);
                    menu.add(mnu);
                } else {
                    if (Boolean.TRUE.equals(a.getValue(AppAction.IS_TOGGLE_BUTTON))) {
                        menu.add(new ActionJCheckboxMenuItem(a));
                    } else {
                        JMenuItem item = new JMenuItem(a);
                        menu.add(item);
                    }
                }
            }
            menuBar.add(menu);
        }
    }
    menuBar.validate();
    menuBar.repaint();
}