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.haskins.cloudtrailviewer.sidebar.EventsChart.java

@Override
public void addCustomMenu() {

    JRadioButtonMenuItem mnuEventName = new JRadioButtonMenuItem("Event Name");
    JRadioButtonMenuItem mnuAwsRegion = new JRadioButtonMenuItem("AWS Region");
    JRadioButtonMenuItem mnuSourceIpAddress = new JRadioButtonMenuItem("Source IP Address");
    JRadioButtonMenuItem mnuUserAgent = new JRadioButtonMenuItem("User Agent");
    JRadioButtonMenuItem mnuEventSource = new JRadioButtonMenuItem("Event Source");
    JRadioButtonMenuItem mnuErrorCode = new JRadioButtonMenuItem("Error Code");
    JRadioButtonMenuItem mnuRecipientAccountId = new JRadioButtonMenuItem("Recipient Account Id");

    mnuEventName.setActionCommand("EventName");
    mnuEventName.addActionListener(this);
    mnuEventName.setSelected(true);/* w w w  .j ava2 s  .  co m*/

    mnuAwsRegion.setActionCommand("AwsRegion");
    mnuAwsRegion.addActionListener(this);

    mnuSourceIpAddress.setActionCommand("SourceIPAddress");
    mnuSourceIpAddress.addActionListener(this);

    mnuUserAgent.setActionCommand("UserAgent");
    mnuUserAgent.addActionListener(this);

    mnuEventSource.setActionCommand("EventSource");
    mnuEventSource.addActionListener(this);

    mnuErrorCode.setActionCommand("ErrorCode");
    mnuErrorCode.addActionListener(this);

    mnuRecipientAccountId.setActionCommand("RecipientAccountId");
    mnuRecipientAccountId.addActionListener(this);

    customGroup.add(mnuEventName);
    customGroup.add(mnuAwsRegion);
    customGroup.add(mnuSourceIpAddress);
    customGroup.add(mnuUserAgent);
    customGroup.add(mnuEventSource);
    customGroup.add(mnuErrorCode);
    customGroup.add(mnuRecipientAccountId);

    JMenu sourceMenu = new JMenu("Event");
    sourceMenu.add(mnuEventName);
    sourceMenu.add(mnuAwsRegion);
    sourceMenu.add(mnuSourceIpAddress);
    sourceMenu.add(mnuUserAgent);
    sourceMenu.add(mnuEventSource);
    sourceMenu.add(mnuErrorCode);
    sourceMenu.add(mnuRecipientAccountId);
    sourceMenu.add(getUserIdentityMenu(customGroup));

    menu.add(sourceMenu);
}

From source file:AddButtonToTabBar.java

public AddButtonToTabBar() {
    super("Browser");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JMenuBar mb = new JMenuBar();
    JMenu mFile = new JMenu("File");
    JMenuItem mi = new JMenuItem("Add Tab");
    ActionListener addTabl = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addTab();//from   www . j  a  v a 2 s  .c o m
        }
    };
    mi.addActionListener(addTabl);
    mFile.add(mi);
    mb.add(mFile);
    setJMenuBar(mb);

    JPanel pnlURL = new JPanel();
    tp = new JTabbedPane();
    addTab();
    getContentPane().add(tp, BorderLayout.CENTER);

    lblStatus = new JLabel(" ");
    getContentPane().add(lblStatus, BorderLayout.SOUTH);

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

From source file:SiteFrame.java

public PageFrame(String name, SiteManager sm) {
    super("Page: " + name, true, true, true, true);
    parent = sm;//w  w  w . ja  v a  2 s.  co  m
    setBounds(50, 50, 300, 150);

    Container contentPane = getContentPane();

    // Create a text area to display the contents of our file in
    // and stick it in a scrollable pane so we can see everything
    ta = new JTextArea();
    JScrollPane jsp = new JScrollPane(ta);
    contentPane.add(jsp, BorderLayout.CENTER);

    JMenuBar jmb = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem saveItem = new JMenuItem("Save");
    saveItem.addActionListener(this);
    fileMenu.add(saveItem);
    jmb.add(fileMenu);
    setJMenuBar(jmb);

    filename = name;
    loadContent();
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java

private JMenu getUserIdentityMenu(ButtonGroup buttonGroup) {

    JRadioButtonMenuItem mnuUiType = new JRadioButtonMenuItem("Type");
    JRadioButtonMenuItem mnuUiPrincipalId = new JRadioButtonMenuItem("Principal Id");
    JRadioButtonMenuItem mnuUiArn = new JRadioButtonMenuItem("Arn");
    JRadioButtonMenuItem mnuUiAccountId = new JRadioButtonMenuItem("Account Id");
    JRadioButtonMenuItem mnuUiAccessKeyId = new JRadioButtonMenuItem("Access Key Id");
    JRadioButtonMenuItem mnuUiUsername = new JRadioButtonMenuItem("Username");
    JRadioButtonMenuItem mnuUiInvokedBy = new JRadioButtonMenuItem("Invoked By");

    mnuUiType.setActionCommand("UserIdentity.Type");
    mnuUiType.addActionListener(this);

    mnuUiPrincipalId.setActionCommand("UserIdentity.PrincipalId");
    mnuUiPrincipalId.addActionListener(this);

    mnuUiArn.setActionCommand("UserIdentity.Arn");
    mnuUiArn.addActionListener(this);

    mnuUiAccountId.setActionCommand("UserIdentity.AccountId");
    mnuUiAccountId.addActionListener(this);

    mnuUiAccessKeyId.setActionCommand("UserIdentity.AccessKeyId");
    mnuUiAccessKeyId.addActionListener(this);

    mnuUiUsername.setActionCommand("UserIdentity.UserName");
    mnuUiUsername.addActionListener(this);

    mnuUiInvokedBy.setActionCommand("UserIdentity.InvokedBy");
    mnuUiInvokedBy.addActionListener(this);

    buttonGroup.add(mnuUiType);/*from   w  ww .  j  a  va2 s.co m*/
    buttonGroup.add(mnuUiPrincipalId);
    buttonGroup.add(mnuUiArn);
    buttonGroup.add(mnuUiAccountId);
    buttonGroup.add(mnuUiAccessKeyId);
    buttonGroup.add(mnuUiUsername);
    buttonGroup.add(mnuUiInvokedBy);

    JMenu userIdentityMenu = new JMenu("User Identity");
    userIdentityMenu.add(mnuUiType);
    userIdentityMenu.add(mnuUiPrincipalId);
    userIdentityMenu.add(mnuUiArn);
    userIdentityMenu.add(mnuUiAccountId);
    userIdentityMenu.add(mnuUiAccessKeyId);
    userIdentityMenu.add(mnuUiUsername);
    userIdentityMenu.add(mnuUiInvokedBy);
    userIdentityMenu.add(getSessionContextMenu(buttonGroup));

    return userIdentityMenu;
}

From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java

/**
 * A standalone demo charting load averages.
 *//* www . j  a  va2 s.c om*/
public JLoadChart() {
    super("JLoadChart");

    jkstat = new NativeJKstat();
    int maxage = 600000;

    String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT");
    ts1 = new TimeSeries("1min " + lavetext);
    ts1.setMaximumItemAge(maxage);
    ts5 = new TimeSeries("5min " + lavetext);
    ts5.setMaximumItemAge(maxage);
    ts15 = new TimeSeries("15min " + lavetext);
    ts15.setMaximumItemAge(maxage);

    updateAccessory();
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ts1);
    dataset.addSeries(ts5);
    dataset.addSeries(ts15);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"),
            KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false);

    XYPlot xyplot = chart.getXYPlot();

    NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT"));
    loadaxis.setAutoRange(true);
    loadaxis.setAutoRangeIncludesZero(true);
    xyplot.setRangeAxis(loadaxis);

    DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME"));
    daxis.setAutoRange(true);
    daxis.setFixedAutoRange(maxage);
    xyplot.setDomainAxis(daxis);

    addWindowListener(new winExit());
    setContentPane(new ChartPanel(chart));

    JMenuBar jm = new JMenuBar();
    JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT"));
    jme.setMnemonic(KeyEvent.VK_F);
    exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X);
    exitItem.addActionListener(this);
    jme.add(exitItem);
    jm.add(jme);

    setJMenuBar(jm);

    pack();
    setVisible(true);
    Timer timer = new Timer(5000, this);
    timer.start();
}

From source file:FramewithMenuShortcut.java

public FramewithMenuShortcut(String title) {
    JMenu fileMenu = new JMenu("File"); // Create File menu
    JMenu elementMenu = new JMenu("Elements"); // Create Elements menu
    fileMenu.setMnemonic('F'); // Create shortcut
    elementMenu.setMnemonic('E'); // Create shortcut
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setJMenuBar(menuBar);//from ww  w.j  a  v  a  2 s.  co  m
    newItem = fileMenu.add("New");
    openItem = fileMenu.add("Open");
    closeItem = fileMenu.add("Close");
    fileMenu.addSeparator();
    saveItem = fileMenu.add("Save");
    saveAsItem = fileMenu.add("Save As...");
    fileMenu.addSeparator();
    printItem = fileMenu.add("Print");
    elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true));
    elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false));
    elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false));
    ButtonGroup types = new ButtonGroup();
    types.add(lineItem);
    types.add(rectangleItem);
    types.add(circleItem);
    elementMenu.addSeparator();
    elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false));
    elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false));
    menuBar.add(fileMenu);
    menuBar.add(elementMenu);
    newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK));
    openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK));
    saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK));
    printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK));
    lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK));
    rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK));
    circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK));
    elementMenu.addSeparator();
    redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK));
    yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK));
    menuBar.add(fileMenu);
    menuBar.add(elementMenu);
}

From source file:gui.ReEditingPopupGraphMousePlugin.java

@SuppressWarnings({ "unchecked", "serial" })
protected void handlePopup(MouseEvent e) {
    final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource();
    final Layout<V, E> layout = vv.getGraphLayout();
    final Graph<V, E> graph = layout.getGraph();
    final Point2D p = e.getPoint();
    final Point2D ivp = p;
    GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();

    if (pickSupport != null) {
        final V vertex = pickSupport.getVertex(layout, ivp.getX(), ivp.getY());
        final E edge = pickSupport.getEdge(layout, ivp.getX(), ivp.getY());
        final PickedState<V> pickedVertexState = vv.getPickedVertexState();
        final PickedState<E> pickedEdgeState = vv.getPickedEdgeState();

        if (vertex != null) {
            Set<V> picked = pickedVertexState.getPicked();
            if (picked.size() > 0) {
                if (graph instanceof UndirectedGraph == false) {
                    JMenu directedMenu = new JMenu("Create Directed Edge");
                    popup.add(directedMenu);
                    for (final V other : picked) {
                        directedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex, EdgeType.DIRECTED);
                                vv.repaint();
                            }//from  w w w. jav  a  2  s.  com
                        });
                    }
                }
                if (graph instanceof DirectedGraph == false) {
                    JMenu undirectedMenu = new JMenu("Create Undirected Edge");
                    popup.add(undirectedMenu);
                    for (final V other : picked) {
                        undirectedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") {
                            public void actionPerformed(ActionEvent e) {
                                graph.addEdge(edgeFactory.create(), other, vertex);
                                vv.repaint();
                            }
                        });
                    }
                }
            }
            popup.add(new AbstractAction("Delete TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    pickedVertexState.pick(vertex, false);
                    graph.removeVertex(vertex);
                    vv.repaint();
                }
            });
        } else if (edge != null) {
            popup.add(new AbstractAction("Delete Edge") {
                public void actionPerformed(ActionEvent e) {
                    pickedEdgeState.pick(edge, false);
                    graph.removeEdge(edge);
                    vv.repaint();
                }
            });
        } else {
            popup.add(new AbstractAction("Create TETRA Vertex") {
                public void actionPerformed(ActionEvent e) {
                    V newVertex = vertexFactory.create();
                    graph.addVertex(newVertex);
                    layout.setLocation(newVertex,
                            vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p));
                    vv.repaint();
                }
            });
        }
        if (popup.getComponentCount() > 0) {
            popup.show(vv, e.getX(), e.getY());
        }
    }
}

From source file:Main.java

public FramewithMenuShortcut() {
    JMenu fileMenu = new JMenu("File"); // Create File menu
    JMenu elementMenu = new JMenu("Elements"); // Create Elements menu
    fileMenu.setMnemonic('F'); // Create shortcut
    elementMenu.setMnemonic('E'); // Create shortcut

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    setJMenuBar(menuBar);/*from  w ww  .java  2s  .  c  o  m*/

    newItem = fileMenu.add("New");
    openItem = fileMenu.add("Open");
    closeItem = fileMenu.add("Close");
    fileMenu.addSeparator();
    saveItem = fileMenu.add("Save");
    saveAsItem = fileMenu.add("Save As...");
    fileMenu.addSeparator();
    printItem = fileMenu.add("Print");
    elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true));
    elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false));
    elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false));
    ButtonGroup types = new ButtonGroup();
    types.add(lineItem);
    types.add(rectangleItem);
    types.add(circleItem);
    elementMenu.addSeparator();
    elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false));
    elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false));
    menuBar.add(fileMenu);
    menuBar.add(elementMenu);
    newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK));
    openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK));
    saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK));
    printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK));
    lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK));
    rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK));
    circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK));
    elementMenu.addSeparator();
    redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK));
    yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK));
    menuBar.add(fileMenu);
    menuBar.add(elementMenu);
}

From source file:TreeUtil.java

/**
 * Make a Menu structure, without the root node. The children of the root
 * node will be added to the specified menu element.
 *//*from   w ww  . j a v  a  2  s  .  com*/
public void getMenus(JMenu menu) {
    int numChild = itsRootNode.getChildCount();
    for (int i = 0; i < numChild; i++) {
        menu.add(getMenus((DefaultMutableTreeNode) itsRootNode.getChildAt(i), menu));
    }
}

From source file:XMLWriteTest.java

public XMLWriteFrame() {
    setTitle("XMLWriteTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    chooser = new JFileChooser();

    // add component to frame

    comp = new RectangleComponent();
    add(comp);//  w w w . j  av  a  2  s.  c o m

    // set up menu bar

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

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

    JMenuItem newItem = new JMenuItem("New");
    menu.add(newItem);
    newItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            comp.newDrawing();
        }
    });

    JMenuItem saveItem = new JMenuItem("Save with DOM/XSLT");
    menu.add(saveItem);
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveDocument();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

    JMenuItem saveStAXItem = new JMenuItem("Save with StAX");
    menu.add(saveStAXItem);
    saveStAXItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveStAX();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

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