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:edu.clemson.cs.nestbed.client.gui.NetworkMonitorFrame.java

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

    video.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            WebCam cam = new WebCam("nestbed.cs.clemson.edu", 9192);
        }//from   ww  w . j av a  2 s. co  m
    });
    menu.add(video);

    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            NetworkMonitorFrame.this.setVisible(false);
        }
    });
    menu.add(new JSeparator());
    menu.add(close);

    return menu;
}

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

private final JMenu buildFileMenu() {
    JMenu file = new JMenu("File");
    JMenuItem exit = new JMenuItem("Exit");

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doExit();//ww  w . j  a  v a  2 s .c o m
        }
    });

    file.add(exit);

    return file;
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * Creates a new DistributionAnalysisDisplayPanel.
 *///www  .java2 s .  c  o m
public DistributionAnalysisDisplayPanel() {
    super(new BorderLayout());
    Language language = Settings.getLanguage();
    this.menuBar = new JMenuBar();
    this.curveFittingMenu = new JMenu(language.get("Curve Fitting"));
    this.curveFittingMenu.setMnemonic(KeyEvent.VK_C);
    this.groupsMenu = new JMenu(language.get("Groups"));
    this.groupsMenu.setMnemonic(KeyEvent.VK_G);
    this.viewMenu = new JMenu(language.get("View"));
    this.viewMenu.setMnemonic(KeyEvent.VK_V);
    this.removeSampleGroupsMenuItem = new JMenuItem(language.get("Reset Sample Groups"), KeyEvent.VK_R);
    this.chooseSampleGroupsMenuItem = new JMenuItem(language.get("Choose Sample Groups"), KeyEvent.VK_C);
    this.fitSelectorPanel = new JPanel(new GridLayout(4, 1));
    this.noFitButton = new JRadioButtonMenuItem(language.get("No Fit"));
    this.robustFitButton = new JRadioButtonMenuItem(language.get("Robust Linear Fit"));
    this.chiSquareFitButton = new JRadioButtonMenuItem(language.get("Chi Square Fit"));
    this.fitButtonGroup = new ButtonGroup();
    this.fitButtonGroup.add(this.noFitButton);
    this.fitButtonGroup.add(this.robustFitButton);
    this.fitButtonGroup.add(this.chiSquareFitButton);
    this.noFitButton.setSelected(true);
    this.hideOutliersViewMenuItem = new JMenuItem(language.get("Hide Current Outliers"));
    this.curveFittingMenu.add(this.noFitButton);
    this.curveFittingMenu.add(this.robustFitButton);
    this.curveFittingMenu.add(this.chiSquareFitButton);
    this.groupsMenu.add(this.removeSampleGroupsMenuItem);
    this.groupsMenu.add(this.chooseSampleGroupsMenuItem);
    this.viewMenu.add(this.hideOutliersViewMenuItem);
    this.chooseSampleGroupsMenuItem.addActionListener(this);
    this.removeSampleGroupsMenuItem.addActionListener(this);
    this.hideOutliersViewMenuItem.addActionListener(this);
    this.add(menuBar, BorderLayout.NORTH);
    this.menuBar.add(this.curveFittingMenu);
    this.menuBar.add(this.groupsMenu);
    this.menuBar.add(this.viewMenu);
}

From source file:com.alvermont.javascript.tools.shell.ShellJSConsole.java

public ShellJSConsole(String[] args) {
    super("Rhino JavaScript Console");

    final JMenuBar menubar = new JMenuBar();
    createFileChooser();//from   w  w  w.jav a  2 s  .c  o  m

    final String[] fileItems = { "Load...", "Close" };
    final String[] fileCmds = { "Load", "Close" };
    final char[] fileShortCuts = { 'L', 'X' };
    final String[] editItems = { "Cut", "Copy", "Paste" };
    final char[] editShortCuts = { 'T', 'C', 'P' };
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');

    final JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic('E');

    for (int i = 0; i < fileItems.length; ++i) {
        final JMenuItem item = new JMenuItem(fileItems[i], fileShortCuts[i]);
        item.setActionCommand(fileCmds[i]);
        item.addActionListener(this);
        fileMenu.add(item);
    }

    for (int i = 0; i < editItems.length; ++i) {
        final JMenuItem item = new JMenuItem(editItems[i], editShortCuts[i]);
        item.addActionListener(this);
        editMenu.add(item);
    }

    final ButtonGroup group = new ButtonGroup();
    menubar.add(fileMenu);
    menubar.add(editMenu);
    setJMenuBar(menubar);
    this.consoleTextArea = new ShellConsoleTextArea(args);

    final JScrollPane scroller = new JScrollPane(this.consoleTextArea);
    setContentPane(scroller);
    this.consoleTextArea.setRows(24);
    this.consoleTextArea.setColumns(80);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
        }
    });
    pack();
    setVisible(true);
    // System.setIn(consoleTextArea.getIn());
    // System.setOut(consoleTextArea.getOut());
    // System.setErr(consoleTextArea.getErr());
    ShellMain.setIn(this.consoleTextArea.getIn());
    ShellMain.setOut(this.consoleTextArea.getOut());
    ShellMain.setErr(this.consoleTextArea.getErr());

    // we don't do this here as we want to separate construction from
    // the run thread
    this.args = args;

    //ShellMain.exec(args);
}

From source file:com.net2plan.gui.GUINet2Plan.java

private static JMenuItem getCurrentMenu(JMenuBar menubar, JMenu parent, String itemName) {
    int pos = itemName.indexOf('|');
    if (pos == -1) {
        if (parent == null)
            throw new RuntimeException("Bad");

        JMenuItem menuItem = new JMenuItem(itemName);
        parent.add(menuItem);//from   w ww  . j  av a 2  s . c o  m

        return menuItem;
    } else {
        String parentName = itemName.substring(0, pos);
        JMenu new_parent = null;

        MenuElement[] children;
        if (menubar != null)
            children = menubar.getSubElements();
        else if (parent != null)
            children = parent.getSubElements();
        else
            throw new RuntimeException("Bad");

        for (MenuElement item : children) {
            if (!(item instanceof JMenu) || !((JMenu) item).getText().equalsIgnoreCase(parentName))
                continue;

            new_parent = (JMenu) item;
            break;
        }

        if (new_parent == null) {
            new_parent = new JMenu(parentName);

            if (menubar != null) {
                if (parentName.equals("Tools")) {
                    menubar.add(new_parent, 1);
                    new_parent.setMnemonic('T');
                } else {
                    menubar.add(new_parent, menubar.getComponentCount() - 1);
                }
            } else if (parent != null) {
                parent.add(new_parent);
            } else {
                throw new RuntimeException("Bad");
            }
        }

        String new_itemName = itemName.substring(pos + 1);

        return getCurrentMenu(null, new_parent, new_itemName);
    }
}

From source file:FillViewportHeightDemo.java

public FillViewportHeightDemo() {
    super("Empty Table DnD Demo");

    tableModel = getDefaultTableModel();
    table = new JTable(tableModel);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setDropMode(DropMode.INSERT_ROWS);

    table.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferSupport support) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!support.isDrop()) {
                return false;
            }//  www.j ava 2  s. c  o  m

            // we only import Strings
            if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferSupport support) {
            // if we can't handle the import, say so
            if (!canImport(support)) {
                return false;
            }

            // fetch the drop location
            JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();

            int row = dl.getRow();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            String[] rowData = data.split(",");
            tableModel.insertRow(row, rowData);

            Rectangle rect = table.getCellRect(row, 0, false);
            if (rect != null) {
                table.scrollRectToVisible(rect);
            }

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt(getNextString(count++), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue(getNextString(100));
    model.insertElementAt(getNextString(count++), 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    dragFrom.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) {
                String text = (String) model.getElementAt(0);
                String[] rowData = text.split(",");
                tableModel.insertRow(table.getRowCount(), rowData);
                model.removeAllElements();
                model.insertElementAt(getNextString(count++), 0);
            }
        }
    });

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    JScrollPane sp = new JScrollPane(table);
    getContentPane().add(sp, BorderLayout.CENTER);
    fillBox = new JCheckBoxMenuItem("Fill Viewport Height");
    fillBox.addActionListener(this);

    JMenuBar mb = new JMenuBar();
    JMenu options = new JMenu("Options");
    mb.add(options);
    setJMenuBar(mb);

    JMenuItem clear = new JMenuItem("Reset");
    clear.addActionListener(this);
    options.add(clear);
    options.add(fillBox);

    getContentPane().setPreferredSize(new Dimension(260, 180));
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTypSortMenu() {
    JMenu typSortMenu = new JMenu("Typ Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override//  w  ww .  jav a  2  s . c o  m
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTypeInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    typSortMenu.add(inOrder);
    typSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTypeSort aTS : ConfigReader.getInstance().getAllTypSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getKabeltypSort()));
        group.add(sw);
        typSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return typSortMenu;
}

From source file:common.AbstractGUI.java

private void createFileMenu() {
    fileMenu = new JMenu("File");

    createFileMenuItems();/*from w  w w. j  a v  a 2 s . c  o m*/

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

    menuBar.add(fileMenu);
}

From source file:com.googlecode.blaisemath.app.MenuConfig.java

/**
 * Build a menu from a given map entry with key the menu name, and value a list
 * or map that determines the menu items.
 * @param name menu name// ww  w.  jav a 2 s . c  o m
 * @param menuContent content of menu
 * @param am string/action mapping
 * @return menu
 */
static JMenu createMenu(String name, List menuContent, Map<String, Action> am) {
    JMenu menu = new JMenu(name);
    for (JMenuItem el : createMenuItemList(menuContent, am)) {
        if (el == null) {
            menu.addSeparator();
        } else {
            menu.add(el);
        }
    }
    return menu;
}

From source file:gdt.jgui.entity.bonddetail.JBondDetailPanel.java

/**
 * Get the context menu.//from w  ww.j a v a  2s .c o m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {

    menu1 = new JMenu("Context");
    menu1.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //   System.out.println("JBondDetailPanel:getConextMenu:BEGIN");
            menu1.removeAll();
            JMenuItem selectItem = new JMenuItem("Select all");
            selectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JItemPanel[] ipa = getItems();
                    if (ipa != null) {
                        for (JItemPanel ip : ipa)
                            ip.setChecked(true);
                    }
                }
            });
            menu1.add(selectItem);
            JMenuItem unselectItem = new JMenuItem("Unselect all");
            unselectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JItemPanel[] ipa = getItems();
                    if (ipa != null) {
                        for (JItemPanel ip : ipa)
                            ip.setChecked(false);
                    }
                }
            });
            menu1.addSeparator();
            JMenuItem doneItem = new JMenuItem("Done");
            doneItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (requesterResponseLocator$ != null) {
                        try {
                            byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                            String responseLocator$ = new String(ba, "UTF-8");
                            JConsoleHandler.execute(console, responseLocator$);
                        } catch (Exception ee) {
                            LOGGER.severe(ee.toString());
                        }
                    } else
                        console.back();

                }

            });
            menu1.add(doneItem);
            menu1.addSeparator();
            addItem = new JMenuItem("Add");
            addItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        Entigrator entigrator = console.getEntigrator(entihome$);

                        JContext adp = (JContext) ExtensionHandler.loadHandlerInstance(entigrator,
                                BondDetailHandler.EXTENSION_KEY, "gdt.jgui.entity.bonddetail.JAddDetailPanel");
                        String adpLocator$ = adp.getLocator();
                        adpLocator$ = Locator.append(adpLocator$, Entigrator.ENTIHOME, entihome$);
                        adpLocator$ = Locator.append(adpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        JConsoleHandler.execute(console, adpLocator$);

                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });
            menu1.add(addItem);
            if (hasToPaste()) {
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        paste();

                    }
                });
                menu1.add(pasteItem);
            }
            if (hasSelectedItems()) {
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {

                            delete();
                            JBondDetailPanel bdp = new JBondDetailPanel();
                            String bdpLocator$ = bdp.getLocator();
                            bdpLocator$ = Locator.append(bdpLocator$, Entigrator.ENTIHOME, entihome$);
                            bdpLocator$ = Locator.append(bdpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            bdpLocator$ = Locator.append(bdpLocator$, JBondsPanel.BOND_KEY, bondKey$);
                            JConsoleHandler.execute(console, bdpLocator$);
                        }
                    }
                });
                menu1.add(deleteItem);
            }

        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu1;
}