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:gdt.jgui.entity.JEntityPrimaryMenu.java

/**
 * Get context menu./*from  w  ww .j a  v  a 2  s .  c  o m*/
 * @return the context menu.
 */
@Override

public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            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();
                }
            });
            menu.add(doneItem);
            if (hasToPaste()) {
                JMenuItem pasteItem = new JMenuItem("Paste components");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        pasteComponents();
                    }
                });
                menu.add(pasteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }

    });

    return menu;
}

From source file:net.sf.jabref.gui.menus.RightClickMenu.java

public RightClickMenu(JabRefFrame frame, BasePanel panel) {
    this.panel = panel;
    JMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypeMenu(panel);
    // Are multiple entries selected?
    boolean multiple = areMultipleEntriesSelected();

    // If only one entry is selected, get a reference to it for adapting the menu.
    BibEntry be = null;//from   www.jav a2  s.  co m
    if (panel.getMainTable().getSelectedRowCount() == 1) {
        be = panel.getMainTable().getSelected().get(0);
    }

    addPopupMenuListener(this);

    JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "...");
    copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key")));
    copySpecialMenu.add(new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}")));
    copySpecialMenu
            .add(new GeneralAction(Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title")));
    copySpecialMenu.add(new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"),
            IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon()));

    add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon()));
    add(copySpecialMenu);
    add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"),
            IconTheme.JabRefIcon.PASTE.getSmallIcon()));
    add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon()));
    add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"),
            IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon()));
    addSeparator();

    add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"),
            IconTheme.JabRefIcon.EMAIL.getSmallIcon()));
    addSeparator();

    JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color"));
    for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) {
        markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem());
    }

    if (multiple) {
        add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"),
                IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()));
        add(markSpecific);
        add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"),
                IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon()));
    } else if (be != null) {
        Optional<String> marked = be.getFieldOptional(InternalBibtexFields.MARKED);
        // We have to check for "" too as the marked field may be empty
        if ((!marked.isPresent()) || marked.get().isEmpty()) {
            add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"),
                    IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon()));
            add(markSpecific);
        } else {
            add(markSpecific);
            add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"),
                    IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon()));
        }
    }

    if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) {
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) {
            JMenu rankingMenu = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), frame);
            add(rankingMenu);
        }

        // TODO: multiple handling for relevance and quality-assurance
        // if multiple values are selected ("if (multiple)"), two options (set / clear) should be offered
        // if one value is selected either set or clear should be offered
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) {
            add(Relevance.getInstance().getValues().get(0).getMenuAction(frame));
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) {
            add(Quality.getInstance().getValues().get(0).getMenuAction(frame));
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) {
            add(Printed.getInstance().getValues().get(0).getMenuAction(frame));
        }

        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) {
            JMenu priorityMenu = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), frame);
            add(priorityMenu);
        }

        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) {
            JMenu readStatusMenu = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(readStatusMenu, ReadStatus.getInstance(), frame);
            add(readStatusMenu);
        }

    }

    addSeparator();

    add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) {
        {
            if (!isFieldSetForSelectedEntry(FieldName.FILE)) {
                this.setEnabled(false);
            }
        }
    });

    add(new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"),
            getFileIconForSelectedEntry()) {
        {
            if (!isFieldSetForSelectedEntry(FieldName.FILE)) {
                this.setEnabled(false);
            }
        }
    });

    add(new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"),
            IconTheme.JabRefIcon.WWW.getSmallIcon()) {
        {
            if (!(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI))) {
                this.setEnabled(false);
            }
        }
    });

    addSeparator();

    add(typeMenu);

    add(new GeneralAction(Actions.MERGE_DOI, Localization.lang("Get BibTeX data from DOI")) {
        {
            if (!(isFieldSetForSelectedEntry(FieldName.DOI))) {
                this.setEnabled(false);
            }
        }
    });
    add(frame.getMassSetField());
    add(new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"),
            IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon()));
    add(frame.getManageKeywords());
    add(new GeneralAction(Actions.MERGE_ENTRIES, Localization.lang("Merge entries") + "...",
            IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()) {

        {
            if (!(areExactlyTwoEntriesSelected())) {
                this.setEnabled(false);
            }
        }

    });

    addSeparator(); // for "add/move/remove to/from group" entries (appended here)

    groupAdd = new JMenuItem(new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group")));
    add(groupAdd);
    groupRemove = new JMenuItem(
            new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group")));
    add(groupRemove);

    groupMoveTo = add(new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group")));
    add(groupMoveTo);

    // create disabledIcons for all menu entries
    frame.createDisabledIconsForMenuEntries(this);
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom,
        boolean tooltips, final ModelMaker modelMaker) {
    super(chart, properties, save, print, zoom, tooltips);
    this.modelMaker = modelMaker;
    // horizontal zoom doesn't work, by setting false we don't get bogus menu item
    //      setHorizontalZoom(false);
    //      setVerticalZoom(true);
    final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y"));
    logYScale.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot p = (CategoryPlot) chart.getPlot();
            Axis oldAxis = p.getRangeAxis();
            if (logYScale.isSelected()) {
                LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"));
                yAxis.setStrictValuesFlag(false);
                p.setRangeAxis(yAxis);/*from w w  w.  j a  va  2 s. c om*/
            } else {
                p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")));
            }
            oldAxis.setPlot(null);
            chartChanged(new ChartChangeEvent(this));
        }
    });
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(logYScale);
    popup.addSeparator();
    select = new JMenu("Select");
    final JMenuItem all = new JMenuItem("All");
    select.add(all);
    final JMenuItem cmDiffer = new JMenuItem("Human marked differ");
    select.add(cmDiffer);
    final JMenuItem cmHold = new JMenuItem("Human marked hold");
    select.add(cmHold);
    final JMenuItem cmMatch = new JMenuItem("Human marked match");
    select.add(cmMatch);
    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
            filter.reset();
            filter.setFromPercentage(rangeFrom);
            filter.setToPercentage(rangeTo);
            Object src = ev.getSource();
            if (src != all) {
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                if (src == cmDiffer) {
                    b[Decision.DIFFER.toInt()] = true;
                } else if (src == cmHold) {
                    b[Decision.HOLD.toInt()] = true;
                } else if (src == cmMatch) {
                    b[Decision.MATCH.toInt()] = true;
                }
                filter.setHumanDecision(b);
            }
            modelMaker.filterMarkedRecordPairList();
        }
    };
    all.addActionListener(l);
    cmDiffer.addActionListener(l);
    cmHold.addActionListener(l);
    cmMatch.addActionListener(l);
    popup.add(select);
    addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent evt) {
            ChartEntity e = evt.getEntity();
            if (e instanceof CategoryItemEntity) {
                CategoryItemEntity c = (CategoryItemEntity) e;
                int cat = c.getCategoryIndex();
                HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot())
                        .getDataset();
                int len = data.getColumnCount();
                float step = 1f / len;
                rangeFrom = cat * step;
                rangeTo = rangeFrom + step;
                ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
                filter.reset();
                filter.setFromPercentage(rangeFrom);
                filter.setToPercentage(rangeTo);
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                int series = c.getSeries();
                if (data.isIncludeHolds() && series != 0) {
                    if (series == 1) {
                        series = 2;
                    } else {
                        series = 1;
                    }
                }
                b[series] = true;
                filter.setHumanDecision(b);
                modelMaker.filterMarkedRecordPairList();

            }
        }

        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });
}

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

private void initFileMenu(JMenuBar menuBar) {
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from  w w w . j a va 2 s. c o  m

    initNewMenu(fileMenu);

    addActionMenuItem("Open", KeyEvent.VK_O, OPEN_ACTION_COMMAND, fileMenu);
    fileMenu.addSeparator();
    this.signMenuItem = addActionMenuItem("Sign", KeyEvent.VK_S, SIGN_ACTION_COMMAND, fileMenu, false);
    this.saveMenuItem = addActionMenuItem("Save", KeyEvent.VK_A, SAVE_ACTION_COMMAND, fileMenu, false);
    this.saveAsMenuItem = addActionMenuItem("Save As", KeyEvent.VK_V, SAVE_AS_ACTION_COMMAND, fileMenu, false);
    this.exportMenuItem = addActionMenuItem("Export", KeyEvent.VK_E, EXPORT_ACTION_COMMAND, fileMenu, false);
    this.closeMenuItem = addActionMenuItem("Close", KeyEvent.VK_C, CLOSE_ACTION_COMMAND, fileMenu, false);
    fileMenu.addSeparator();
    addActionMenuItem("Exit", KeyEvent.VK_X, EXIT_ACTION_COMMAND, fileMenu);
}

From source file:MainClass.java

public MainClass() {
    super();//from   w ww. java2 s  .co m

    setChannel(currentNumber);

    numberLabel.setHorizontalAlignment(JLabel.CENTER);
    numberLabel.setFont(new Font("Serif", Font.PLAIN, 32));

    getContentPane().add(numberLabel, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16));
    getContentPane().add(buttonPanel, BorderLayout.CENTER);
    buttonPanel.add(new JButton(upAction));
    buttonPanel.add(new JButton(gotoFavoriteAction));
    buttonPanel.add(new JButton(downAction));
    buttonPanel.add(new JButton(setFavoriteAction));

    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Number");
    menu.add(new JMenuItem(upAction));
    menu.add(new JMenuItem(downAction));
    menu.addSeparator();
    menu.add(new JMenuItem(gotoFavoriteAction));
    menu.add(new JMenuItem(setFavoriteAction));
    mb.add(menu);
    setJMenuBar(mb);
}

From source file:org.simbrain.plot.piechart.PieChartGui.java

/**
 * Creates the menu bar./*  w w w .j  a  va 2  s . c  o m*/
 */
private void createAttachMenuBar() {
    JMenuBar bar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    for (Action action : actionManager.getOpenSavePlotActions()) {
        fileMenu.add(action);
    }
    fileMenu.addSeparator();
    fileMenu.add(new CloseAction(this.getWorkspaceComponent()));

    JMenu editMenu = new JMenu("Edit");
    JMenuItem preferences = new JMenuItem("Preferences...");
    preferences.addActionListener(this);
    preferences.setActionCommand("dialog");
    editMenu.add(preferences);

    JMenu helpMenu = new JMenu("Help");
    ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/pie_chart.html");
    JMenuItem helpItem = new JMenuItem(helpAction);
    helpMenu.add(helpItem);

    bar.add(fileMenu);
    bar.add(editMenu);
    bar.add(helpMenu);

    getParentFrame().setJMenuBar(bar);
}

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);/*  ww  w  . j  a  v a 2 s  .  c om*/

    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:de.burrotinto.jKabel.dispalyAS.DisplayK.java

@Bean(name = "trommeln")
public JMenu allTrommel(IDBWrapper db) {
    JMenu m = new JMenu("Trommeln");

    db.getAllKabeltypen().forEach(new Consumer<IKabeltypE>() {
        @Override//  www . j  a v  a2s . c o m
        public void accept(IKabeltypE iKabeltypE) {
            iKabeltypE.getTrommeln().forEach(new Consumer<ITrommelE>() {
                @Override
                public void accept(ITrommelE iTrommelE) {
                    m.add(iTrommelE.getId() + " " + iTrommelE.getTrommelnummer());
                }
            });
        }
    });
    return m;
}

From source file:TextCutPaste.java

/**
 * Create an Edit menu to support cut/copy/paste.
 *///from w  w w . j  a v a2s  . co m
public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;
    JMenuBar menuBar = new JMenuBar();
    JMenu mainMenu = new JMenu("Edit");
    mainMenu.setMnemonic(KeyEvent.VK_E);

    menuItem = new JMenuItem(new DefaultEditorKit.CutAction());
    menuItem.setText("Cut");
    menuItem.setMnemonic(KeyEvent.VK_T);
    mainMenu.add(menuItem);

    menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
    menuItem.setText("Copy");
    menuItem.setMnemonic(KeyEvent.VK_C);
    mainMenu.add(menuItem);

    menuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
    menuItem.setText("Paste");
    menuItem.setMnemonic(KeyEvent.VK_P);
    mainMenu.add(menuItem);

    menuBar.add(mainMenu);
    return menuBar;
}

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();
        }/*ww w  .j  av a  2 s .  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);
}