Example usage for javax.swing JMenu add

List of usage examples for javax.swing JMenu add

Introduction

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

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Creates a new menu item attached to the specified Action object and appends it to the end of this menu.

Usage

From source file:ImageViewer.java

public ImageViewerFrame() {
    setTitle("ImageViewer");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // use a label to display the images
    label = new JLabel();
    add(label);//from  ww  w  .ja va2 s .  c  o  m

    // set up the file chooser
    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // set up the menu bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // show file chooser dialog
            int result = chooser.showOpenDialog(null);

            // if file selected, set it as icon of the label
            if (result == JFileChooser.APPROVE_OPTION) {
                String name = chooser.getSelectedFile().getPath();
                label.setIcon(new ImageIcon(name));
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:SampleDesktop.java

protected void createMenuBar() {
    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Frames");

    menu.add(new AddFrameAction(true)); // add "upper" frame
    menu.add(new AddFrameAction(false)); // add "lower" frame
    menu.add(new TileAction(desk)); // add tiling capability

    setJMenuBar(mb);//from w w  w .  jav  a 2 s.  c om
    mb.add(menu);
}

From source file:CutAndPasteDemo.java

public CutAndPasteDemo() {
    super("Cut And Paste Demonstration");

    clipboard = getToolkit().getSystemClipboard();

    GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font font = new Font("LucidaSans", Font.PLAIN, 15);
    textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25);
    textArea2 = new JTextArea("<Paste text here>", 5, 25);
    textArea1.setFont(font);// w  w  w. j  a  va2  s  .  co m
    textArea2.setFont(font);

    JPanel jPanel = new JPanel();
    JMenuBar jMenuBar = new JMenuBar();
    JMenuItem cutItem = new JMenuItem("Cut");
    JMenuItem pasteItem = new JMenuItem("Paste");
    JMenu jMenu = new JMenu("Edit");
    jMenu.add(cutItem);
    jMenu.add(pasteItem);

    cutItem.addActionListener(new CutActionListener());
    pasteItem.addActionListener(new PasteActionListener());

    jMenuBar.add(jMenu);
    jPanel.add(jMenuBar);

    jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
    jPanel.add(textArea1);
    jPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    jPanel.add(textArea2);

    getContentPane().add(jPanel, BorderLayout.CENTER);
}

From source file:fr.crnan.videso3d.ihm.TrajectoryProjectionGUI.java

public TrajectoryProjectionGUI(List<VidesoTrack> tracks, Globe globe) {

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);//from ww w . ja  va2s  .  c o m

    JMenu mnParamtres = new JMenu("Paramtres");
    menuBar.add(mnParamtres);

    JMenuItem mntmNewMenuItem = new JMenuItem("New menu item");
    mnParamtres.add(mntmNewMenuItem);

    double ref = TracksStatsProducer.computeReferenceAltitude(tracks);
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (VidesoTrack t : tracks) {
        dataset.addSeries(TracksStatsProducer.computeDevelopedPath(t, ref, false, globe));
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Projection", "Distance (NM)", "Altitude (FL)", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
    pack();
}

From source file:SimpleMenu.java

/** The convenience method that creates menu panes */
public static JMenu create(ResourceBundle bundle, String menuname, String[] itemnames,
        ActionListener listener) {
    // Get the menu title from the bundle. Use name as default label.
    String menulabel;/*ww w .  j  a  v  a  2  s  .  com*/
    try {
        menulabel = bundle.getString(menuname + ".label");
    } catch (MissingResourceException e) {
        menulabel = menuname;
    }

    // Create the menu pane.
    JMenu menu = new JMenu(menulabel);

    // For each named item in the menu.
    for (int i = 0; i < itemnames.length; i++) {
        // Look up the label for the item, using name as default.
        String itemlabel;
        try {
            itemlabel = bundle.getString(menuname + "." + itemnames[i] + ".label");
        } catch (MissingResourceException e) {
            itemlabel = itemnames[i];
        }

        JMenuItem item = new JMenuItem(itemlabel);

        // Look up an accelerator for the menu item
        try {
            String acceleratorText = bundle.getString(menuname + "." + itemnames[i] + ".accelerator");
            item.setAccelerator(KeyStroke.getKeyStroke(acceleratorText));
        } catch (MissingResourceException e) {
        }

        // Register an action listener and command for the item.
        if (listener != null) {
            item.addActionListener(listener);
            item.setActionCommand(itemnames[i]);
        }

        // Add the item to the menu.
        menu.add(item);
    }

    // Return the automatically created localized menu.
    return menu;
}

From source file:de.dakror.virtualhub.server.ServerFrame.java

public void init() {
    initFiles();//  ww  w  .jav  a2s  .  c om

    logArea = new JTextArea();
    logArea.setWrapStyleWord(true);
    logArea.setEditable(false);
    logArea.setLineWrap(true);
    DefaultCaret caret = (DefaultCaret) logArea.getCaret();
    caret.setSelectionVisible(false);
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    wrap = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    setContentPane(wrap);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Aktionen");
    menu.add(new JMenuItem(
            new AbstractAction("Protokoll leeren", new ImageIcon(getClass().getResource("/img/trash.png"))) {
                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    logArea.setText("");
                    log("Protokoll geleert.");
                }
            }));
    menu.add(logEnabled = new JCheckBoxMenuItem("Protokoll aktiviert",
            new ImageIcon(getClass().getResource("/img/log.png")), true));
    menu.add(packetLogEnabled = new JCheckBoxMenuItem("Paketverkehr protokollieren",
            new ImageIcon(getClass().getResource("/img/traffic.png")), false));
    menu.addSeparator();
    menu.add(new JMenuItem(new AbstractAction("Backup-Einstellungen",
            new ImageIcon(getClass().getResource("/img/backup_edit.png"))) {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                BackupEditDialog.show();
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }));

    menuBar.add(menu);
    setJMenuBar(menuBar);
}

From source file:ZipTest.java

public ZipTestFrame() {
    setTitle("ZipTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the menu and the Open and Exit menu items
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");

    JMenuItem openItem = new JMenuItem("Open");
    menu.add(openItem);
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("."));
            int r = chooser.showOpenDialog(ZipTestFrame.this);
            if (r == JFileChooser.APPROVE_OPTION) {
                zipname = chooser.getSelectedFile().getPath();
                fileCombo.removeAllItems();
                scanZipFile();/*  w w w  .  ja  v  a  2 s . co m*/
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    menuBar.add(menu);
    setJMenuBar(menuBar);

    // add the text area and combo box
    fileText = new JTextArea();
    fileCombo = new JComboBox();
    fileCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadZipFile((String) fileCombo.getSelectedItem());
        }
    });

    add(fileCombo, BorderLayout.SOUTH);
    add(new JScrollPane(fileText), BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu(new AbstractAction("File") {

        @Override//from   w  ww  .j  av  a2  s  . c om
        public void actionPerformed(ActionEvent arg0) {
            System.out.println("action");

        }

    });
    bar.add(menu);

    menu.add(new JMenuItem("Close"));
    menu.add(new JSeparator()); // SEPARATOR
    menu.add(new AbstractAction("Exit") {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            System.out.println("action");

        }

    });

    setJMenuBar(bar);
    add(new JLabel("A placeholder"));

    pack();
    setSize(300, 300);
    setVisible(true);
}

From source file:ec.ui.view.res.ResidualsView.java

private JMenu buildMenu() {
    JMenu result = new JMenu();

    result.add(grid.getActionMap().get(ATsCollectionView.COPY_ALL_ACTION)).setText("Copy series");

    JMenu export = new JMenu("Export image to");
    export.add(ChartCommand.printImage().toAction(chartPanel)).setText("Printer...");
    export.add(ChartCommand.copyImage().toAction(chartPanel)).setText("Clipboard");
    export.add(ChartCommand.saveImage().toAction(chartPanel)).setText("File...");
    result.add(export);//from w ww .  j  a v  a  2s. c  om

    return result;
}

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);
    file.addSeparator();//from w w  w  .java2 s . c  o  m
    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);
}