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:MenuDemo.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu menuFile = new JMenu("File");
    menuFile.setMnemonic('f');

    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setIcon(new ImageIcon("file_new.gif"));
    menuItem.setMnemonic('n');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("New");
        }//from  w  ww .ja va2  s .  c o  m
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Open...");
    menuItem.setIcon(new ImageIcon("file_open.gif"));
    menuItem.setMnemonic('o');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MenuDemo.this.repaint();
            if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION)
                return;
            System.out.println(fileChooser.getSelectedFile());
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Save...");
    menuItem.setIcon(new ImageIcon("file_save.gif"));
    menuItem.setMnemonic('s');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Save...");
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuFile.addSeparator();

    menuItem = new JMenuItem("Exit");
    menuItem.setMnemonic('x');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);
    menuBar.add(menuFile);

    ActionListener fontListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateMonitor();
        }
    };

    JMenu mFont = new JMenu("Font");
    mFont.setMnemonic('o');

    ButtonGroup group = new ButtonGroup();
    menus = new JMenuItem[FontNames.length];
    for (int i = 0; i < FontNames.length; i++) {
        int m = i + 1;
        menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]);
        boolean selected = (i == 0);
        menus[i].setSelected(selected);
        menus[i].setMnemonic('1' + i);
        menus[i].setFont(fontArray[i]);
        menus[i].addActionListener(fontListener);
        group.add(menus[i]);
        mFont.add(menus[i]);
    }

    mFont.addSeparator();

    boldMenuItem = new JCheckBoxMenuItem("Bold");
    boldMenuItem.setMnemonic('b');
    Font fn = fontArray[1].deriveFont(Font.BOLD);
    boldMenuItem.setFont(fn);
    boldMenuItem.setSelected(false);
    boldMenuItem.addActionListener(fontListener);
    mFont.add(boldMenuItem);

    italicMenuItem = new JCheckBoxMenuItem("Italic");
    italicMenuItem.setMnemonic('i');
    fn = fontArray[1].deriveFont(Font.ITALIC);
    italicMenuItem.setFont(fn);
    italicMenuItem.setSelected(false);
    italicMenuItem.addActionListener(fontListener);
    mFont.add(italicMenuItem);

    menuBar.add(mFont);

    return menuBar;
}

From source file:J3dSwingFrame.java

/**
 * Construct the test frame with a menubar and 3D canvas
 *///from  ww  w  .  ja v a 2s  .c o m
public J3dSwingFrame() {
    super("Java3D Tester");

    // Disable lightweight menus
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    JMenuBar menubar = new JMenuBar();

    // File menu
    JMenu file_menu = new JMenu("File");
    menubar.add(file_menu);

    close_menu = new JMenuItem("Exit");
    close_menu.addActionListener(this);
    file_menu.add(close_menu);

    setJMenuBar(menubar);

    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    GraphicsConfiguration config = device.getBestConfiguration(template);

    canvas = new Canvas3D(config);

    // add the canvas to this frame. Since this is the only thing added to
    // the main frame we don't care about layout managers etc.

    getContentPane().add(canvas, "Center");

    constructWorld();

    setSize(600, 600);
}

From source file:gov.nij.er.ui.EntityResolutionDemo.java

private JMenuBar buildMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.add(new ExcelLoadAction());
    menu.add(new SaveParametersAction());
    menu.add(new LoadParametersAction());
    menu.add(new QuitAction());
    menuBar.add(menu);/*w  w w .  j  a v  a 2  s . c om*/
    return menuBar;
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private JMenuItem addActionMenuItem(String text, int mnemonic, String actionCommand, JMenu menu,
        boolean enabled) {
    JMenuItem menuItem = new JMenuItem(text);
    menuItem.setMnemonic(mnemonic);//from www .j ava2 s .  co m
    menuItem.setActionCommand(actionCommand);
    menuItem.addActionListener(this);
    menuItem.setEnabled(enabled);
    menu.add(menuItem);
    return menuItem;
}

From source file:daylightchart.gui.DaylightChartGui.java

private void createActions(final JMenuBar menuBar, final JToolBar toolBar) {
    final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.Actions")); //$NON-NLS-1$
    menu.setMnemonic('A');

    for (final LocationsListOperation operation : LocationsListOperation.values()) {
        final GuiAction action = operation.getAction(this);
        menu.add(action);
    }/*from   www .  j  a va 2 s. c  o m*/

    menu.addSeparator();
    menu.add(new GetCountriesFilesAction());
    menu.add(new GetUSStatesFilesAction());

    menu.addSeparator();
    menu.add(new CloseCurrentTabAction(locationsTabbedPane));

    menuBar.add(menu);
}

From source file:ec.nbdemetra.chainlinking.outlineview.ChainLinkingChart.java

private JMenu newExportMenu() {
    DemetraUI demetraUI = DemetraUI.getDefault();

    JMenu rslt = new JMenu("Export image to");
    rslt.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O));

    JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel));
    copy.setText("Clipboard...");
    copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD));

    JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel));
    file.setText("File...");
    file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O));

    rslt.add(copy);
    rslt.add(file);//from  w  ww  .j av a 2s. co m

    return rslt;
}

From source file:com.diversityarrays.dal.server.ServerGui.java

public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot,
        DalServerPreferences prefs) {/*from   ww  w  . j  a v a  2  s.c om*/

    this.serverIconImage = serverIconImage;
    this.dalServerFactory = factory;
    this.wwwRoot = wwwRoot;
    this.preferences = prefs;

    JMenuBar menuBar = new JMenuBar();

    JMenu serverMenu = new JMenu("Server");
    menuBar.add(serverMenu);
    serverMenu.add(serverStartAction);
    serverMenu.add(serverStopAction);
    serverMenu.add(exitAction);

    JMenu commandMenu = new JMenu("Command");
    menuBar.add(commandMenu);
    commandMenu.add(doSql);

    JMenu urlMenu = new JMenu("URL");
    menuBar.add(urlMenu);
    urlMenu.add(new JMenuItem(copyDalUrlAction));
    urlMenu.add(new JMenuItem(showDalUrlQRcodeAction));

    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    messages.setFont(GuiUtil.createMonospacedFont(12));
    messages.setEditable(false);

    setServer(svr);

    quietOption.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean q = quietOption.isSelected();
            if (server != null) {
                server.setQuiet(q);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();

    JButton clear = new JButton(new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            messages.setText("");
        }
    });

    final boolean[] follow = new boolean[] { true };
    final JCheckBox followTail = new JCheckBox("Follow", follow[0]);

    followTail.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            follow[0] = followTail.isSelected();
        }
    });

    final OutputStream os = new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            char ch = (char) b;
            messages.append(new Character(ch).toString());
            if (ch == '\n' && follow[0]) {
                verticalScrollBar.setValue(verticalScrollBar.getMaximum());
            }
        }
    };

    TeePrintStream pso = new TeePrintStream(System.out, os);
    TeePrintStream pse = new TeePrintStream(System.err, os);

    System.setErr(pse);
    System.setOut(pso);

    Box box = Box.createHorizontalBox();
    box.add(clear);
    box.add(followTail);
    box.add(quietOption);
    box.add(Box.createHorizontalGlue());

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(BorderLayout.NORTH, box);
    bottom.add(BorderLayout.SOUTH, statusInfoLine);

    Container cp = getContentPane();
    cp.add(BorderLayout.CENTER, scrollPane);
    cp.add(BorderLayout.SOUTH, bottom);

    pack();
    setSize(640, 480);

    final MemoryUsageMonitor mum = new MemoryUsageMonitor();
    mum.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            statusInfoLine.setMessage(mum.getMemoryUsage());
        }
    });

    if (server == null) {
        // If initial server is null, allow user to specify
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                serverStartAction.actionPerformed(null);
            }
        });
    } else {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                ensureDatabaseInitialisedThenStartServer();
            }
        });
    }
}

From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java

private JMenu newExportMenu() {
    DemetraUI demetraUI = DemetraUI.getDefault();

    JMenu result = new JMenu("Export image to");
    result.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O));

    JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel));
    copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD));
    copy.setText("Clipboard");

    JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel));
    file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O));
    file.setText("File...");

    result.add(copy);
    result.add(file);//  w  w w.j  a  v a2  s. c o m

    return result;
}

From source file:daylightchart.gui.DaylightChartGui.java

private void createFileMenu(final JMenuBar menuBar, final JToolBar toolBar) {

    final GuiAction openLocationsFile = new OpenLocationsFileAction(this);
    final GuiAction saveLocationsFile = new SaveLocationsFileAction(this);
    final GuiAction saveChart = new SaveChartAction(this);
    final GuiAction printChart = new PrintChartAction(locationsTabbedPane);

    final ExitAction exit = new ExitAction(this, Messages.getString("DaylightChartGui.Menu.File.Exit")); //$NON-NLS-1$

    final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.File")); //$NON-NLS-1$
    menu.setMnemonic('F');

    recentLocationsMenu = new JMenu(Messages.getString("DaylightChartGui.Menu.File.RecentLocations")); //$NON-NLS-1$
    menu.setMnemonic('R');

    menu.add(openLocationsFile);
    menu.add(saveLocationsFile);// w  ww.  j a va 2 s. c  om
    menu.addSeparator();
    menu.add(saveChart);
    if (!isSlimUi()) {
        menu.add(printChart);
    }
    menu.addSeparator();
    menu.add(recentLocationsMenu);
    menu.addSeparator();
    menu.add(exit);
    menuBar.add(menu);

    toolBar.add(openLocationsFile);
    toolBar.add(saveLocationsFile);
    toolBar.addSeparator();
    toolBar.add(saveChart);
    toolBar.add(printChart);
    toolBar.addSeparator();

}

From source file:erigo.filepump.FilePump.java

public JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);/*from w w  w.  j  a  v a 2  s .c om*/
    JMenuItem menuItem = new JMenuItem("Settings...");
    menu.add(menuItem);
    menuItem.addActionListener(this);
    menuItem = new JMenuItem("Exit");
    menu.add(menuItem);
    menuItem.addActionListener(this);
    return menuBar;
}