Example usage for javax.swing JMenuBar add

List of usage examples for javax.swing JMenuBar add

Introduction

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

Prototype

public JMenu add(JMenu c) 

Source Link

Document

Appends the specified menu to the end of the menu bar.

Usage

From source file:net.sf.mzmine.modules.visualization.msms.MsMsVisualizerWindow.java

public MsMsVisualizerWindow(RawDataFile dataFile, Range<Double> rtRange, Range<Double> mzRange,
        IntensityType intensityType, NormalizationType normalizationType, Double minPeakInt,
        ParameterSet parameters) {//  ww w .j a v a  2s  .co  m

    super("MS/MS visualizer: [" + dataFile.getName() + "]");

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    this.dataFile = dataFile;
    this.tooltipMode = true;

    dataset = new MsMsDataSet(dataFile, rtRange, mzRange, intensityType, normalizationType, minPeakInt, this);

    toolBar = new MsMsToolBar(this);
    add(toolBar, BorderLayout.EAST);

    IDAPlot = new MsMsPlot(this, dataFile, this, dataset, rtRange, mzRange);
    add(IDAPlot, BorderLayout.CENTER);

    bottomPanel = new MsMsBottomPanel(this, dataFile, parameters);
    add(bottomPanel, BorderLayout.SOUTH);

    updateTitle();

    // After we have constructed everything, load the peak lists into the
    // bottom panel
    bottomPanel.rebuildPeakListSelector();

    MZmineCore.getDesktop().addPeakListTreeListener(bottomPanel);

    // Add the Windows menu
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new WindowsMenu());
    setJMenuBar(menuBar);

    pack();

    // get the window settings parameter
    ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(MsMsVisualizerModule.class);
    WindowSettingsParameter settings = paramSet.getParameter(MsMsParameters.windowSettings);

    // update the window and listen for changes
    settings.applySettingsToWindow(this);
    this.addComponentListener(settings);
}

From source file:InternalFrameDemo.java

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

    // Set up the lone menu.
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);

    // Set up the first menu item.
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(this);
    menu.add(menuItem);//  ww  w.jav a2s .c o  m

    // Set up the second menu item.
    menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    return menuBar;
}

From source file:ImageViewer.java

public ImageViewer() {
    setTitle("ImageViewer");
    setSize(300, 400);//from w  ww.  j  a va 2s  .c o  m

    JMenuBar mbar = new JMenuBar();
    JMenu m = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    m.add(openItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    m.add(exitItem);
    mbar.add(m);
    setJMenuBar(mbar);

    label = new JLabel();
    Container contentPane = getContentPane();
    contentPane.add(label, "Center");
}

From source file:com.l2jfree.config.gui.Configurator.java

public Configurator(ConfigClassInfo configClassInfo) {
    _configClassInfo = configClassInfo;//from  www .  j ava  2 s  . co m

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    {
        final JMenuBar jMenuBar = new JMenuBar();

        {
            jMenuBar.add(getLoadJButton());
        }
        {
            jMenuBar.add(getRefreshJButton());
        }
        {
            jMenuBar.add(Box.createHorizontalGlue());
        }
        {
            jMenuBar.add(getSaveJButton());
        }
        {
            jMenuBar.add(getStoreJButton());
        }

        setJMenuBar(jMenuBar);
    }

    {
        final JPanel jPanel = new JPanel();

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

        {
            for (ConfigFieldInfo info : _configClassInfo.getConfigFieldInfos()) {
                final ConfigFieldInfoView view = new ConfigFieldInfoView(info);

                // LOW implement

                jPanel.add(view);
            }
        }

        add(new JScrollPane(jPanel));
    }

    pack();
    setSize(600, 400);
    setLocationByPlatform(true);
    setVisible(true);
}

From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java

private void initMenu() {
    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    JMenuItem open = new JMenuItem("Open Project Folder", KeyEvent.VK_O);
    open.setMnemonic(KeyEvent.VK_O);
    open.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            promptForGradleBaseDir();//from   w  w w  .java2 s . c  om
            refresh();
        }
    });
    fileMenu.add(open);

    JMenuItem refresh = new JMenuItem("Refresh");
    refresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            refresh();
        }
    });
    fileMenu.add(refresh);

    fileMenu.addSeparator();
    JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X);
    exit.setMnemonic(KeyEvent.VK_X);
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    fileMenu.add(exit);

    setJMenuBar(menuBar);
}

From source file:DataExchangeTest.java

public DataExchangeFrame() {
    setTitle("DataExchangeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // construct a File menu

    JMenuBar mbar = new JMenuBar();
    setJMenuBar(mbar);//from  w  w w .ja v  a 2 s. c om
    JMenu fileMenu = new JMenu("File");
    mbar.add(fileMenu);

    // add Connect and Exit menu items

    JMenuItem connectItem = new JMenuItem("Connect");
    connectItem.addActionListener(new ConnectAction());
    fileMenu.add(connectItem);

    // The Exit item exits the program

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

    textArea = new JTextArea();
    add(new JScrollPane(textArea), BorderLayout.CENTER);
}

From source file:OptPaneComparison.java

public OptPaneComparison(final String message) {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    final int msgType = JOptionPane.QUESTION_MESSAGE;
    final int optType = JOptionPane.OK_CANCEL_OPTION;
    final String title = message;

    setSize(350, 200);/*from   w ww .ja  v  a 2 s  .  co  m*/

    // Create a desktop for internal frames
    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);

    // Add a simple menu bar
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);

    JMenu menu = new JMenu("Dialog");
    JMenu imenu = new JMenu("Internal");
    mb.add(menu);
    mb.add(imenu);
    final JMenuItem construct = new JMenuItem("Constructor");
    final JMenuItem stat = new JMenuItem("Static Method");
    final JMenuItem iconstruct = new JMenuItem("Constructor");
    final JMenuItem istat = new JMenuItem("Static Method");
    menu.add(construct);
    menu.add(stat);
    imenu.add(iconstruct);
    imenu.add(istat);

    // Create our JOptionPane. We're asking for input, so we call
    // setWantsInput.
    // Note that we cannot specify this via constructor parameters.
    optPane = new JOptionPane(message, msgType, optType);
    optPane.setWantsInput(true);

    // Add a listener for each menu item that will display the appropriate
    // dialog/internal frame
    construct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JDialog d = optPane.createDialog(desk, title);
            d.setVisible(true);

            respond(getOptionPaneValue());
        }
    });

    stat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });

    iconstruct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JInternalFrame f = optPane.createInternalFrame(desk, title);
            f.setVisible(true);

            // Listen for the frame to close before getting the value from
            // it.
            f.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent ev) {
                    if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
                            && (ev.getNewValue() == Boolean.TRUE)) {
                        respond(getOptionPaneValue());
                    }
                }
            });
        }
    });

    istat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });
}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java

/**
 * Initialize the Frame./*from   w  ww  .ja v  a  2s . c o m*/
 *
 * @param title the window title
 * @param statsMenu an optional menu listing available statistics
 */
protected void init(String title, JMenu statsMenu) {
    setTitle(title);

    setContentPane(new ChartPanel(kbc.getChart()));

    addWindowListener(new winExit());

    JMenuBar jm = new JMenuBar();
    jm.add(fileMenu());
    if (!(jkstat instanceof SequencedJKstat)) {
        jm.add(sleepMenu());
    }
    if (statsMenu != null) {
        jm.add(statsMenu);
    }
    setJMenuBar(jm);

    pack();
    setVisible(true);
}

From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java

public IntensityPlotWindow(ParameterSet parameters) {

    PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()
            .getMatchingPeakLists()[0];/*from  w w w.j ava 2  s  .c o  m*/

    String title = "Intensity plot [" + peakList + "]";
    String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString();
    String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString();

    // create dataset
    dataset = new IntensityPlotDataset(parameters);

    // create new JFreeChart
    logger.finest("Creating new chart instance");
    Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue();
    boolean isCombo = (xAxisValueSource instanceof ParameterWrapper)
            && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter));
    if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) {

        chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();

        // set renderer
        StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true);
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    } else {

        chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        XYPlot plot = (XYPlot) chart.getPlot();

        XYErrorRenderer renderer = new XYErrorRenderer();
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

    }

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this);
    add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    Plot plot = chart.getPlot();

    // set shape provider
    IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier();
    plot.setDrawingSupplier(shapeSupplier);

    // set y axis properties
    NumberAxis yAxis;
    if (plot instanceof CategoryPlot)
        yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis();
    else
        yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis();
    NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat();
    if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT)
        yAxisFormat = MZmineCore.getConfiguration().getRTFormat();
    yAxis.setNumberFormatOverride(yAxisFormat);

    setTitle(title);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    // Add the Windows menu
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new WindowsMenu());
    setJMenuBar(menuBar);

    pack();

    // get the window settings parameter
    ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class);
    WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings);

    // update the window and listen for changes
    settings.applySettingsToWindow(this);
    this.addComponentListener(settings);

}

From source file:XPathTest.java

public XPathFrame() {
        setTitle("XPathTest");

        JMenu fileMenu = new JMenu("File");
        JMenuItem openItem = new JMenuItem("Open");
        openItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                openFile();//from  www.ja v a  2 s .  c o 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);

        ActionListener listener = new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                evaluate();
            }
        };
        expression = new JTextField(20);
        expression.addActionListener(listener);
        JButton evaluateButton = new JButton("Evaluate");
        evaluateButton.addActionListener(listener);

        typeCombo = new JComboBox(new Object[] { "STRING", "NODE", "NODESET", "NUMBER", "BOOLEAN" });
        typeCombo.setSelectedItem("STRING");

        JPanel panel = new JPanel();
        panel.add(expression);
        panel.add(typeCombo);
        panel.add(evaluateButton);
        docText = new JTextArea(10, 40);
        result = new JTextField();
        result.setBorder(new TitledBorder("Result"));

        add(panel, BorderLayout.NORTH);
        add(new JScrollPane(docText), BorderLayout.CENTER);
        add(result, BorderLayout.SOUTH);

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            JOptionPane.showMessageDialog(this, e);
        }

        XPathFactory xpfactory = XPathFactory.newInstance();
        path = xpfactory.newXPath();
        pack();
    }