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:uk.co.petertribble.jkstat.demo.JLoadChart.java

/**
 * A standalone demo charting load averages.
 *//*from ww w  . java  2s  .  c o  m*/
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:de.hstsoft.sdeep.view.MainWindow.java

private void createUI() {
    mapView = new MapView();
    getContentPane().add(mapView, BorderLayout.CENTER);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*  ww  w  . j  ava  2s. co  m*/

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

    JMenuItem mntmOpenSaveGame = new JMenuItem("Open Savegame");
    mntmOpenSaveGame.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openFileChooser();
        }
    });
    mnFile.add(mntmOpenSaveGame);

    mnFile.addSeparator();

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    mnFile.add(mntmExit);

    JMenu mnView = new JMenu("View");
    menuBar.add(mnView);

    final JCheckBoxMenuItem menuItemShowinfo = new JCheckBoxMenuItem("ShowInfo");
    menuItemShowinfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showInfo = menuItemShowinfo.isSelected();
            mapView.setShowInfo(showInfo);
        }
    });
    menuItemShowinfo.setSelected(mapView.isShowInfo());
    mnView.add(menuItemShowinfo);

    final JCheckBoxMenuItem menuItemShowgrid = new JCheckBoxMenuItem("ShowGrid");
    menuItemShowgrid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showGrid = menuItemShowgrid.isSelected();
            mapView.setShowGrid(showGrid);
        }
    });
    menuItemShowgrid.setSelected(mapView.isShowGrid());
    mnView.add(menuItemShowgrid);

    final JCheckBoxMenuItem menuItemNotes = new JCheckBoxMenuItem("ShowNotes");
    menuItemNotes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showNotes = menuItemNotes.isSelected();
            mapView.setShowNotes(showNotes);
        }
    });
    menuItemNotes.setSelected(mapView.isShowNotes());
    mnView.add(menuItemNotes);

    final JCheckBoxMenuItem menuItemAnimals = new JCheckBoxMenuItem("ShowAnimals");
    menuItemAnimals.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean showAnimals = menuItemAnimals.isSelected();
            mapView.setShowAnimals(showAnimals);
        }
    });
    menuItemAnimals.setSelected(mapView.isShowAnimals());
    mnView.add(menuItemAnimals);

    mnView.addSeparator();

    menuItemFileWatcher = new JCheckBoxMenuItem("Auto refresh");
    menuItemFileWatcher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean enabled = menuItemFileWatcher.isSelected();
            toggleAutoRefresh(enabled);
        }
    });
    mnView.add(menuItemFileWatcher);

    mnView.addSeparator();

    JMenuItem menuItemResetView = new JMenuItem("Reset view");
    menuItemResetView.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            mapView.resetView();
        }
    });
    mnView.add(menuItemResetView);

    JMenu mnInfo = new JMenu("Info");
    menuBar.add(mnInfo);

    JMenuItem mntmInfo = new JMenuItem("About");
    mntmInfo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showInfo();
        }
    });
    mnInfo.add(mntmInfo);

}

From source file:components.TextComponentDemo.java

public TextComponentDemo() {
    super("TextComponentDemo");

    //Create the text pane and configure it.
    textPane = new JTextPane();
    textPane.setCaretPosition(0);/*ww w .j  a v a 2  s. c  om*/
    textPane.setMargin(new Insets(5, 5, 5, 5));
    StyledDocument styledDoc = textPane.getStyledDocument();
    if (styledDoc instanceof AbstractDocument) {
        doc = (AbstractDocument) styledDoc;
        doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
    } else {
        System.err.println("Text pane's document isn't an AbstractDocument!");
        System.exit(-1);
    }
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(200, 200));

    //Create the text area for the status log and configure it.
    changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    //Create a split pane for the change log and the text area.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    //Create the status area.
    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    //Add the components.
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    //Set up the menu bar.
    actions = createActionTable(textPane);
    JMenu editMenu = createEditMenu();
    JMenu styleMenu = createStyleMenu();
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

    //Add some key bindings.
    addBindings();

    //Put the initial text into the text pane.
    initDocument();
    textPane.setCaretPosition(0);

    //Start watching for undoable edits and caret changes.
    doc.addUndoableEditListener(new MyUndoableEditListener());
    textPane.addCaretListener(caretListenerLabel);
    doc.addDocumentListener(new MyDocumentListener());
}

From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java

public PerformanceResultDialog(PerformanceResultsData data) {

    super((Frame) null, "Performance test results");
    setSize(1000, 800);/*from   www  . ja v  a  2  s. c o  m*/

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    JMenuItem savePerformanceMenuItem = new JMenuItem("Save Performance");
    fileMenu.add(savePerformanceMenuItem);
    savePerformanceMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle("Save as PNG...");
            int result = fileChooser.showSaveDialog(PerformanceResultDialog.this);
            if (JFileChooser.APPROVE_OPTION == result) {
                File file = fileChooser.getSelectedFile();
                try {
                    ChartUtilities.saveChartAsPNG(file, performanceChart, 1024, 768);
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage());
                }
            }
        }

    });
    JMenuItem saveMemoryMenuItem = new JMenuItem("Save Memory");
    fileMenu.add(saveMemoryMenuItem);
    saveMemoryMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle("Save as PNG...");
            int result = fileChooser.showSaveDialog(PerformanceResultDialog.this);
            if (JFileChooser.APPROVE_OPTION == result) {
                File file = fileChooser.getSelectedFile();
                try {
                    ChartUtilities.saveChartAsPNG(file, memoryChart, 1024, 768);
                } catch (IOException e) {
                    JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage());
                }
            }
        }

    });

    // memory chart
    memoryChart = getMemoryChart(data.getIntervalSize(), data.getMemory());

    // performance chart
    performanceChart = getPerformanceChart(data.getIntervalSize(), data.getPerformance(),
            data.getExpectedRevokedCount());

    Container container = getContentPane();
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    if (null != performanceChart) {
        splitPane.setTopComponent(new ChartPanel(performanceChart));
    }
    if (null != memoryChart) {
        splitPane.setBottomComponent(new ChartPanel(memoryChart));
    }
    splitPane.setDividerLocation(getHeight() / 2);
    splitPane.setDividerSize(1);
    container.add(splitPane);

    setVisible(true);
}

From source file:de.huberlin.cuneiform.compiler.debug.DebugDispatcher.java

private void addMenu() {

    JMenuBar menuBar;
    JMenu fileMenu;//from  w  ww .j a v  a2 s .  com
    JMenu helpMenu;
    JMenuItem aboutItem;

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

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

    openItem = new JMenuItem("Open File ...");
    fileMenu.add(openItem);

    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);

    helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    aboutItem = new JMenuItem("About Cuneiform");
    helpMenu.add(aboutItem);
}

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Initialize the contents of the frame.
 *///  w ww .  ja  v a 2 s. com
private void initialize() {
    log.info("Plant Evaluator started");
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;
    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 mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$
    menuBar.add(mnTools);

    JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$
    mntmPostprocessing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    });
    mnTools.add(mntmPostprocessing);

    JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$
    mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL);
    mntmPlot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            DialogUtil.getInstance().showPlotTypeSelection();
        }
    });

    mnTools.add(mntmPlot);

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

public FramewithAboutMenu(String title) {
    JMenuBar menuBar = new JMenuBar();
    setTitle(title);/*from  w w  w. j a  v  a  2 s.  co  m*/
    setJMenuBar(menuBar);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JMenu fileMenu = new JMenu("File");
    JMenu elementMenu = new JMenu("Elements");
    JMenu helpMenu = new JMenu("Help");
    fileMenu.setMnemonic('F');
    elementMenu.setMnemonic('E');
    helpMenu.setMnemonic('H');
    JMenuItem aboutItem = new JMenuItem("About");
    helpMenu.add(aboutItem);
    menuBar.add(helpMenu);
}

From source file:eu.delving.sip.Application.java

private JMenuBar createMenuBar() {
    JMenuBar bar = new JMenuBar();
    bar.add(allFrames.getViewMenu());
    bar.add(expertMenu);/*  w  w w  .  j  a v a2 s .co m*/
    return bar;
}

From source file:TableRowColumnTest.java

public PlanetTableFrame() {
    setTitle("TableRowColumnTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new DefaultTableModel(cells, columnNames) {
        public Class<?> getColumnClass(int c) {
            return cells[0][c].getClass();
        }/*from  www  .  j  a va  2s  .c  o m*/
    };

    table = new JTable(model);

    table.setRowHeight(100);
    table.getColumnModel().getColumn(COLOR_COLUMN).setMinWidth(250);
    table.getColumnModel().getColumn(IMAGE_COLUMN).setMinWidth(100);

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    sorter.setComparator(COLOR_COLUMN, new Comparator<Color>() {
        public int compare(Color c1, Color c2) {
            int d = c1.getBlue() - c2.getBlue();
            if (d != 0)
                return d;
            d = c1.getGreen() - c2.getGreen();
            if (d != 0)
                return d;
            return c1.getRed() - c2.getRed();
        }
    });
    sorter.setSortable(IMAGE_COLUMN, false);
    add(new JScrollPane(table), BorderLayout.CENTER);

    removedRowIndices = new HashSet<Integer>();
    removedColumns = new ArrayList<TableColumn>();

    final RowFilter<TableModel, Integer> filter = new RowFilter<TableModel, Integer>() {
        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
            return !removedRowIndices.contains(entry.getIdentifier());
        }
    };

    // create menu

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

    JMenu selectionMenu = new JMenu("Selection");
    menuBar.add(selectionMenu);

    rowsItem = new JCheckBoxMenuItem("Rows");
    columnsItem = new JCheckBoxMenuItem("Columns");
    cellsItem = new JCheckBoxMenuItem("Cells");

    rowsItem.setSelected(table.getRowSelectionAllowed());
    columnsItem.setSelected(table.getColumnSelectionAllowed());
    cellsItem.setSelected(table.getCellSelectionEnabled());

    rowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setRowSelectionAllowed(rowsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(rowsItem);

    columnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setColumnSelectionAllowed(columnsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(columnsItem);

    cellsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setCellSelectionEnabled(cellsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(cellsItem);

    JMenu tableMenu = new JMenu("Edit");
    menuBar.add(tableMenu);

    JMenuItem hideColumnsItem = new JMenuItem("Hide Columns");
    hideColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedColumns();
            TableColumnModel columnModel = table.getColumnModel();

            // remove columns from view, starting at the last
            // index so that column numbers aren't affected

            for (int i = selected.length - 1; i >= 0; i--) {
                TableColumn column = columnModel.getColumn(selected[i]);
                table.removeColumn(column);

                // store removed columns for "show columns" command

                removedColumns.add(column);
            }
        }
    });
    tableMenu.add(hideColumnsItem);

    JMenuItem showColumnsItem = new JMenuItem("Show Columns");
    showColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // restore all removed columns
            for (TableColumn tc : removedColumns)
                table.addColumn(tc);
            removedColumns.clear();
        }
    });
    tableMenu.add(showColumnsItem);

    JMenuItem hideRowsItem = new JMenuItem("Hide Rows");
    hideRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            for (int i : selected)
                removedRowIndices.add(table.convertRowIndexToModel(i));
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(hideRowsItem);

    JMenuItem showRowsItem = new JMenuItem("Show Rows");
    showRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            removedRowIndices.clear();
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(showRowsItem);

    JMenuItem printSelectionItem = new JMenuItem("Print Selection");
    printSelectionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            System.out.println("Selected rows: " + Arrays.toString(selected));
            selected = table.getSelectedColumns();
            System.out.println("Selected columns: " + Arrays.toString(selected));
        }
    });
    tableMenu.add(printSelectionItem);
}

From source file:TextComponentDemo.java

public TextComponentDemo() {
    super("TextComponentDemo");

    // Create the text pane and configure it.
    textPane = new JTextPane();
    textPane.setCaretPosition(0);/*from w ww  . j a  v a 2  s .co  m*/
    textPane.setMargin(new Insets(5, 5, 5, 5));
    StyledDocument styledDoc = textPane.getStyledDocument();
    if (styledDoc instanceof AbstractDocument) {
        doc = (AbstractDocument) styledDoc;
        //doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
    } else {
        System.err.println("Text pane's document isn't an AbstractDocument!");
        System.exit(-1);
    }
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(200, 200));

    // Create the text area for the status log and configure it.
    changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    // Create a split pane for the change log and the text area.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    // Create the status area.
    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    // Add the components.
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    // Set up the menu bar.
    createActionTable(textPane);
    JMenu editMenu = createEditMenu();
    JMenu styleMenu = createStyleMenu();
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

    // Add some key bindings.
    addBindings();

    // Put the initial text into the text pane.
    initDocument();

    // Start watching for undoable edits and caret changes.
    doc.addUndoableEditListener(new MyUndoableEditListener());
    textPane.addCaretListener(caretListenerLabel);
    doc.addDocumentListener(new MyDocumentListener());
}