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:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java

private JMenu createAxesPropMenu() {
    JMenu menu = new JMenu("Axes Scale");
    menu.add(createMenuItem("Log-Linear", ACTION_LOG_LINEAR));
    menu.add(createMenuItem("Log-Log", ACTION_LOG_LOG));
    menu.add(createMenuItem("Linear-Log", ACTION_LINEAR_LOG));
    menu.add(createMenuItem("Linear-Linear", ACTION_LINEAR_LINEAR));
    return menu;/*from  www.  j  ava 2  s . co m*/
}

From source file:coreferenceresolver.gui.MarkupGUI.java

public MarkupGUI() throws IOException {
    highlightPainters = new ArrayList<>();

    for (int i = 0; i < COLORS.length; ++i) {
        DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(
                COLORS[i]);/*from   w w  w  . j a v a  2s. c om*/
        highlightPainters.add(highlightPainter);
    }

    defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath"));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new BorderLayout());
    this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    //create menu items
    JMenuItem importMenuItem = new JMenuItem("Import");

    JMenuItem exportMenuItem = new JMenuItem("Export");

    fileMenu.add(importMenuItem);
    fileMenu.add(exportMenuItem);

    menuBar.add(fileMenu);

    this.setJMenuBar(menuBar);

    ScrollablePanel mainPanel = new ScrollablePanel();
    mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    //IMPORT BUTTON
    importMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //                MarkupGUI.reviewElements.clear();
            //                MarkupGUI.markupReviews.clear();                
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose your markup file");
            markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException, BadLocationException {
                        readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath());
                        for (int i = 0; i < markupReviews.size(); ++i) {
                            mainPanel.add(newReviewPanel(markupReviews.get(i), i));
                        }
                        return null;
                    }

                    protected void done() {
                        MarkupGUI.this.revalidate();
                        d.dispose();
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs      
    exportMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose where your markup file saved");
            markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException {
                        for (Review review : markupReviews) {
                            generateNPsRef(review);
                        }
                        int i = 0;
                        for (ReviewElement reviewElement : reviewElements) {
                            int j = 0;
                            for (Element element : reviewElement.elements) {
                                String newType = element.typeSpinner.getValue().toString();
                                if (newType.equals("Object")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(0);
                                } else if (newType.equals("Attribute")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(3);
                                } else if (newType.equals("Other")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(1);
                                } else if (newType.equals("Candidate")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(2);
                                }
                                ++j;
                            }
                            ++i;
                        }
                        initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator
                                + "markup.out.txt");
                        return null;
                    }

                    protected void done() {
                        d.dispose();
                        try {
                            Desktop.getDesktop()
                                    .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath()));
                        } catch (IOException ex) {
                            Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    JScrollPane scrollMainPane = new JScrollPane(mainPanel);
    scrollMainPane.getVerticalScrollBar().setUnitIncrement(16);
    scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
    scrollMainPane.setSize(this.getWidth(), this.getHeight());
    this.setResizable(false);
    this.add(scrollMainPane, BorderLayout.CENTER);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    this.pack();
}

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 om
    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:jchrest.gui.Shell.java

private JMenu createDataMenu() {
    this._dataMenu = new JMenu("Data");
    this._dataMenu.setMnemonic(KeyEvent.VK_D);

    JMenu scriptedExperimentSubMenu = new JMenu("Load Scripted Experiment");
    scriptedExperimentSubMenu.add(
            new LoadScriptedExperimentAction(this, "Paired Associate: Fast/Slow", "PairedAssociateFastSlow"));
    this._dataMenu.add(scriptedExperimentSubMenu);

    this._dataMenu.add(new LoadPreExperimentDataAction(this))
            .setAccelerator(KeyStroke.getKeyStroke('P', java.awt.Event.CTRL_MASK, false));
    this._dataMenu.add(new LoadExperimentDataAction(this))
            .setAccelerator(KeyStroke.getKeyStroke('O', java.awt.Event.CTRL_MASK, false));
    return this._dataMenu;
}

From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java

private JMenu createLinePropMenu() {
    JMenuItem symMenu = new JMenuItem("Show/Hide Symbols");
    symMenu.setActionCommand(ACTION_SHOW_SYMBOLS);
    symMenu.addActionListener(plotPanelListener);

    JMenuItem lineMenu = new JMenuItem("Show/Hide Lines");
    lineMenu.setActionCommand(ACTION_HIDE_LINES);
    lineMenu.addActionListener(plotPanelListener);

    JMenu menu = new JMenu("Line Properties");
    menu.add(symMenu);
    menu.add(lineMenu);//from   w ww .  ja v  a2  s .  c o  m
    return menu;
}

From source file:DOMTreeTest.java

public DOMTreeFrame() {
        setTitle("DOMTreeTest");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

        JMenu fileMenu = new JMenu("File");
        JMenuItem openItem = new JMenuItem("Open");
        openItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                openFile();//from w  ww  . ja  va 2  s  .co m
            }
        });
        fileMenu.add(openItem);

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

        JMenuBar menuBar = new JMenuBar();
        menuBar.add(fileMenu);
        setJMenuBar(menuBar);
    }

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

@SuppressWarnings("unchecked")
private void showVarsPicker() {
    final MultiValueMap namespaces = this.variableHelper.getNamespaces();

    List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size());
    sortedNames.addAll(namespaces.keySet());
    Collections.sort(sortedNames, new Comparator<String>() {
        public int compare(String o1, String o2) {
            if (o1 == null) {
                return -1;
            }/*  www .  jav  a 2s .co  m*/
            if (o2 == null) {
                return 1;
            }
            return o1.compareTo(o2);
        };
    });

    final JPopupMenu menu = new JPopupMenu();
    for (final String name : sortedNames) {
        final JMenu subMenu = new JMenu(name);
        menu.add(subMenu);
        subMenu.addMenuListener(new MenuListener() {
            private Timer timer;

            public void menuSelected(MenuEvent e) {

                subMenu.removeAll();
                subMenu.add(new PleaseWaitAction());

                ActionListener menuPopulator = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (subMenu.isPopupMenuVisible()) {
                            subMenu.removeAll();
                            for (Object namespaceO : namespaces.getCollection(name)) {
                                String namespace = (String) namespaceO;
                                logger.debug("Resolving variables for namespace ".concat(namespace));
                                int nbItems = 0;
                                for (String key : variableHelper.keySet(namespace)) {
                                    subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key),
                                            (String) key));
                                    nbItems++;
                                }
                                if (nbItems == 0) {
                                    subMenu.add(new DummyAction());
                                    logger.debug("No variables found.");
                                }
                            }
                            subMenu.revalidate();
                            subMenu.getPopupMenu().pack();
                        }
                    }
                };
                timer = new Timer(700, menuPopulator);
                timer.setRepeats(false);
                timer.start();
            }

            public void menuDeselected(MenuEvent e) {
                timer.stop();
            }

            public void menuCanceled(MenuEvent e) {
                timer.stop();
            }
        });
    }

    menu.show(varNameText, 0, varNameText.getHeight());
}

From source file:edu.clemson.cs.nestbed.client.gui.MoteDetailFrame.java

private JMenu buildFileMenu() {
    JMenu menu = new JMenu("File");
    JMenuItem close = new JMenuItem("Close");

    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MoteDetailFrame.this.setVisible(false);
        }// ww w.  j  a  v  a 2 s . c o  m
    });
    menu.add(close);

    return menu;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JMenu buildMenu() {
    JMenu menu = new JMenu();
    JMenuItem item;//  w w  w  .j  a v a  2 s.co  m
    item = new JMenuItem(new CopyAction());
    item.setText("Copy data");
    menu.add(item);

    return menu;
}

From source file:jchrest.gui.Shell.java

private JMenu createShellMenu() {
    JMenuItem exit = new JMenuItem("Exit", new ImageIcon(Shell.class.getResource("icons/Stop16.gif")));
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);//from www  . java 2s. c  om
        }
    });

    JMenu menu = new JMenu("Shell");
    menu.setMnemonic(KeyEvent.VK_S);
    menu.add(new AboutAction(this));
    menu.getItem(0).setMnemonic(KeyEvent.VK_A);
    menu.add(new LookFeelAction(this));
    menu.getItem(1).setMnemonic(KeyEvent.VK_T);
    menu.add(new JSeparator());
    menu.add(exit);
    menu.getItem(3).setMnemonic(KeyEvent.VK_X);

    menu.getItem(0).setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK, false));
    menu.getItem(3).setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false));
    return menu;
}