Example usage for javax.swing JMenuItem JMenuItem

List of usage examples for javax.swing JMenuItem JMenuItem

Introduction

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

Prototype

public JMenuItem(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the specified Action.

Usage

From source file:de.peterspan.csv2db.AppWindow.java

private void initialize() {
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;//from  www  . j  a va2s. c o  m
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:edu.gcsc.vrl.jfreechart.JFXPlotContainerType.java

protected void updateChartPanel(Container container, final JFreeChart jFreeChart) {

    if (chartPanel != null) {
        chartContainer.remove(chartPanel);
    }/*w  ww. jav a 2 s .c o  m*/

    chartPanel = new ChartPanel(jFreeChart);
    chartContainer.add(chartPanel);

    JPopupMenu menu = chartPanel.getPopupMenu();

    menu.addSeparator();
    JMenuItem item1 = new JMenuItem("Export");
    item1.setActionCommand("export_chart");
    item1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            String cmd = e.getActionCommand();

            if (cmd.equals("export_chart")) {

                try {
                    new JFExport().openExportDialog(jFreeChart);
                } catch (Exception e1) {
                    e1.printStackTrace(System.err);
                }

            }
        }
    });
    menu.add(item1);

    revalidate();
}

From source file:de.genvlin.plugins.jfreechart.JFreeChartPluginImpl.java

public void sendRequest(RequestEvent ri) {
    if (ri.getActionContextReason() == PluginPool.SELECTED_COLS) {
        selected = (VectorInterface[]) ((GTablePanel) ri.getSource()).getSelectedVectors();
        JMenu menu = new JMenu(getName());
        JMenuItem item = new JMenuItem(getMenuName());
        item.setActionCommand(getMenuName());
        menu.add(item);// w  ww.j  av  a 2  s.  c  o  m
        item.addActionListener(this);

        item = new JMenuItem(LINEAR_REG);
        item.setActionCommand(LINEAR_REG);
        menu.add(item);
        item.addActionListener(this);

        ((JPopupMenu) ri.getObject()).add(menu);
    }
}

From source file:it.unibas.spicygui.controllo.provider.intermediatezone.MyPopupProviderConnectionFunc.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;/*from ww  w  . ja v  a  2s  . co  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(NbBundle.getMessage(Costanti.class, Costanti.IMPLIED));
    //        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:DragColorTextFieldDemo.java

public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;/*ww  w.  j av  a  2s .c  o  m*/
    JMenuBar menuBar = new JMenuBar();
    JMenu mainMenu = new JMenu("Edit");
    mainMenu.setMnemonic(KeyEvent.VK_E);

    menuItem = new JMenuItem(new DefaultEditorKit.CutAction());
    menuItem.setText("Cut");
    menuItem.setMnemonic(KeyEvent.VK_T);
    mainMenu.add(menuItem);
    menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
    menuItem.setText("Copy");
    menuItem.setMnemonic(KeyEvent.VK_C);
    mainMenu.add(menuItem);
    menuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
    menuItem.setText("Paste");
    menuItem.setMnemonic(KeyEvent.VK_P);
    mainMenu.add(menuItem);

    menuBar.add(mainMenu);
    return menuBar;
}

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  . ja  va 2s. c  o m
    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:it.unibas.spicygui.controllo.provider.MyPopupSceneMatcher.java

private void createPopupMenuGlassPane() {
    popupMenu = new JPopupMenu("Popup menu");
    JMenuItem item;/*from   w w  w.  ja va2 s . com*/

    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.ACTION_SLIDER));
    item.setActionCommand(Costanti.ACTION_SLIDER);
    item.addActionListener(this);
    popupMenu.add(item);

}

From source file:components.TabComponentsDemo.java

private void initMenu() {
    JMenuBar menuBar = new JMenuBar();
    //create Options menu
    tabComponentsItem = new JCheckBoxMenuItem("Use TabComponents", true);
    tabComponentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK));
    tabComponentsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < pane.getTabCount(); i++) {
                if (tabComponentsItem.isSelected()) {
                    initTabComponent(i);
                } else {
                    pane.setTabComponentAt(i, null);
                }/*from w  ww .ja v a  2 s . com*/
            }
        }
    });
    scrollLayoutItem = new JCheckBoxMenuItem("Set ScrollLayout");
    scrollLayoutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
    scrollLayoutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (pane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) {
                pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
            } else {
                pane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
            }
        }
    });
    JMenuItem resetItem = new JMenuItem("Reset JTabbedPane");
    resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    resetItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            runTest();
        }
    });

    JMenu optionsMenu = new JMenu("Options");
    optionsMenu.add(tabComponentsItem);
    optionsMenu.add(scrollLayoutItem);
    optionsMenu.add(resetItem);
    menuBar.add(optionsMenu);
    setJMenuBar(menuBar);
}

From source file:de.biomedical_imaging.ij.plot.HistogramPlotter.java

public HistogramPlotter(String title, String xlabel, double[][] data, int numberOfParticles,
        int meanTrackLength, IDatasetCreator datacreator) {

    super(title);
    this.title = title;
    this.xlabel = xlabel;
    this.numberOfParticles = numberOfParticles;
    this.meanTrackLength = meanTrackLength;
    IntervalXYDataset xydataset = datacreator.create(data);
    boolean isbarplot = (datacreator instanceof BarplotDataset);
    txt = new JLabel();
    Font f = new Font("Verdana", Font.PLAIN, 12);
    txt.setFont(f);/* www .j  a  v  a2  s  . co m*/

    JFreeChart chart = createChart(xydataset, isbarplot);

    ChartPanel chartPanel = new ChartPanel(chart);

    txt.setText(formatSettingsString());

    main = new JPanel();
    main.setPreferredSize(new java.awt.Dimension(500, 350));
    main.add(chartPanel);
    main.add(txt);
    setContentPane(main);

    setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));

    pack();
    setVisible(true);

    JMenuItem savebutton = ((JMenuItem) chartPanel.getPopupMenu().getComponent(3));
    chartPanel.getPopupMenu().remove(3); // Remove Save button
    //ActionListener al = savebutton.getActionListeners()[0];
    savebutton = new JMenuItem("Save as png");
    //savebutton.removeActionListener(al);
    savebutton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub

            try {
                JFileChooser saveFile = new JFileChooser();
                saveFile.setAcceptAllFileFilterUsed(false);
                saveFile.addChoosableFileFilter(new FileNameExtensionFilter("Images", "png"));
                int userSelection = saveFile.showSaveDialog(main);
                if (userSelection == JFileChooser.APPROVE_OPTION) {
                    BufferedImage bi = ScreenImage.createImage(main);
                    File fileToSave = saveFile.getSelectedFile();
                    String filename = fileToSave.getName();
                    int i = filename.lastIndexOf('.');
                    String suffix = filename.substring(i + 1);
                    String path = fileToSave.getAbsolutePath();
                    if (!(suffix.equals("png"))) {
                        path += ".png";
                    }
                    ScreenImage.writeImage(bi, path);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                IJ.log("" + e.getMessage());
            }

        }
    });
    chartPanel.getPopupMenu().insert(savebutton, 3);

}

From source file:net.sf.housekeeper.swing.MainFrame.java

/**
 * Builds the menus.// ww w . ja  v a  2 s  .c om
 * 
 * @return The created menu bar. Is not null.
 */
private JMenuBar buildMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    //File Menu
    final String fileMenuLabel = LocalisationManager.INSTANCE.getText("gui.menu.file");
    final JMenu menuFile = new JMenu(fileMenuLabel);
    menuBar.add(menuFile);

    menuFile.add(new JMenuItem(new LoadDataAction()));
    menuFile.add(new JMenuItem(new SaveDataAction()));
    menuFile.addSeparator();
    menuFile.add(new JMenuItem(new ExitAction()));

    //Help Menu
    final String helpMenuString = LocalisationManager.INSTANCE.getText("gui.menu.help");
    final JMenu menuHelp = new JMenu(helpMenuString);
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(menuHelp);

    menuHelp.add(new JMenuItem(new AboutDialogAction()));

    return menuBar;
}