Example usage for javax.swing JTable setComponentPopupMenu

List of usage examples for javax.swing JTable setComponentPopupMenu

Introduction

In this page you can find the example usage for javax.swing JTable setComponentPopupMenu.

Prototype

@BeanProperty(preferred = true, description = "Popup to show")
public void setComponentPopupMenu(JPopupMenu popup) 

Source Link

Document

Sets the JPopupMenu for this JComponent.

Usage

From source file:net.pandoragames.far.ui.swing.FileListPanel.java

private void init(SwingConfig config, ComponentRepository componentRepository) {

    this.setLayout(new BorderLayout());

    this.setBorder(
            BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING));

    tableModel = componentRepository.getTableModel();
    componentRepository.getResetDispatcher().addResetable(tableModel);
    componentRepository.getSearchBaseListener().addResetable(tableModel);
    componentRepository.getUndoListener().setTableModel(tableModel);

    JTable fileListTable = componentRepository.getFileSetTable();
    int totalWidth = fileListTable.getPreferredSize().width;
    fileListTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    fileListTable.setColumnSelectionAllowed(true);
    fileListTable.getTableHeader().addMouseListener(new TableHeaderMouseListener());
    fileListTable.getTableHeader().getColumnModel().getColumn(0)
            .setHeaderRenderer(new TableHeaderCheckBoxColumnRenderer());
    fileListPopupMenu = new FileListPopupMenu(fileListTable, tableModel, componentRepository, config);
    fileListTable.setComponentPopupMenu(fileListPopupMenu);
    fileListTable.addMouseListener(new FileViewOpener(fileListTable, componentRepository.getRootWindow(),
            config, componentRepository));
    fileListTable.getColumnModel().getColumn(0).setPreferredWidth(20);
    fileListTable.getColumnModel().getColumn(0).setMaxWidth(20);
    fileListTable.getColumnModel().getColumn(1).setCellRenderer(new TargetFileListTableCellRenderer());
    fileListTable.getColumnModel().getColumn(1).setPreferredWidth(2 * totalWidth / 5);
    fileListTable.getColumnModel().getColumn(2).setCellRenderer(new PathColumnRenderer());
    fileListTable.getColumnModel().getColumn(3).setCellRenderer(new InfoColumnRenderer(config));
    JScrollPane scrollPane = new JScrollPane(fileListTable);
    this.add(scrollPane, BorderLayout.CENTER);

    SelectCounter fileCounter = new SelectCounter();
    fileCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    fileCounter.setForeground(Color.GRAY);
    ErrorCounter errorCounter = new ErrorCounter();
    errorCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    JPanel counterLine = new JPanel();
    counterLine.setLayout(new BorderLayout());
    counterLine.add(fileCounter, BorderLayout.WEST);
    counterLine.add(errorCounter, BorderLayout.EAST);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setEnabled(false);// w ww  .j a v a  2 s. c  o  m
    progressBar.setMaximumSize(new Dimension(100, 20));
    progressBar.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    componentRepository.getProgressBarUpdater().setProgressBar(progressBar);
    JPanel progressBarPanel = new JPanel();
    progressBarPanel.add(progressBar);
    counterLine.add(progressBarPanel, BorderLayout.CENTER);

    counterLine.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
    this.add(counterLine, BorderLayout.SOUTH);

    tableModel.addTableModelListener(new ColumnCountListener(fileCounter));
    tableModel.addTableModelListener(errorCounter);
    componentRepository.getResetDispatcher().addResetable(fileCounter);
    componentRepository.getSearchBaseListener().addResetable(fileCounter);
    componentRepository.getOperationCallBackListener().addComponentStartReseted(fileCounter,
            OperationType.FIND);
    componentRepository.getResetDispatcher().addResetable(errorCounter);
    componentRepository.getSearchBaseListener().addResetable(errorCounter);

    viewAction = new ActionView(componentRepository, config);
}

From source file:org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel.java

private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)

    // register the right click menu
    JTable table = getTable();
    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem variabilizeItem = new JMenuItem(JMeterUtils.getResString("transform_into_variable"));
    variabilizeItem.addActionListener(new ActionListener() {
        @Override//from   ww w . j a va 2 s  .c o  m
        public void actionPerformed(ActionEvent e) {
            transformNameIntoVariable();
        }
    });
    popupMenu.add(variabilizeItem);
    table.setComponentPopupMenu(popupMenu);
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void addColumn() {
    if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) {
        return;/*from  www  .  jav  a  2s.co  m*/
    }

    if (columnGroupCount != 0) {
        panelBox.add(Box.createHorizontalStrut(7));
    }

    final int tableIndex = columnGroupCount;

    final DataTableModel tableModel = new DataTableModel();
    final JTable table = new JTable(tableModel);

    table.setDragEnabled(true);
    table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount));

    if (showThresholdCheckBoxGroup.isSelected()) {
        tableModel.setThresholdVisible(true);
    }

    if (showMinMaxCheckBoxGroup.isSelected()) {
        tableModel.setMaxMinVisible(true);

        table.getColumn("Min").setCellRenderer(doubleCellRenderer);
        table.getColumn("Max").setCellRenderer(doubleCellRenderer);
    }

    table.getColumn("Value").setCellRenderer(dataCellRenderer);

    tables.add(table);
    tableModels.add(tableModel);

    JScrollPane tableScrollPane = new JScrollPane(table);
    panelBox.add(tableScrollPane);

    // popup menu for panel
    JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TransferHandler.getCopyAction().actionPerformed(
                    new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
        }
    });
    popupMenu.add(copyMenuItem);

    popupMenu.addSeparator();

    JMenuItem printMenuItem = new JMenuItem("Print...");
    printMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.FIT_WIDTH);
            } catch (PrinterException pe) {
            }
        }
    });
    popupMenu.add(printMenuItem);
    popupMenu.addSeparator();

    final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false);
    showMaxMinMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMaxMinVisible(showMaxMinMenuItem.isSelected());
        }
    });
    showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem);
    popupMenu.add(showMaxMinMenuItem);

    final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false);
    showThresholdMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setThresholdVisible(showThresholdMenuItem.isSelected());
        }
    });
    showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem);
    popupMenu.add(showThresholdMenuItem);

    popupMenu.addSeparator();

    JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row");
    blankRowMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tableModel.addBlankRow();
        }
    });
    popupMenu.add(blankRowMenuItem);

    final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows");
    removeSelectedRowsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeSelectedRows(tableIndex);
        }
    });
    popupMenu.add(removeSelectedRowsMenuItem);

    popupMenu.addSeparator();

    JMenu numberOfColumnsMenu = new JMenu("Number of columns");
    numberOfColumnsMenu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent me) {
            JMenu menu = (JMenu) me.getSource();
            for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) {
                JMenuItem menuItem = menu.getItem(j);
                boolean selected = (j == (columnGroupCount - 1));
                menuItem.setSelected(selected);
            }
        }

        public void menuDeselected(MenuEvent me) {
        }

        public void menuCanceled(MenuEvent me) {
        }
    });

    for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) {
        final int number = i + 1;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setNumberOfColumns(number);
            }
        });
        numberOfColumnsMenu.add(item);
    }
    popupMenu.add(numberOfColumnsMenu);

    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean anyRowsSelected = table.getSelectedRowCount() > 0;
            copyMenuItem.setEnabled(anyRowsSelected);
            removeSelectedRowsMenuItem.setEnabled(anyRowsSelected);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    table.setComponentPopupMenu(popupMenu);
    tableScrollPane.setComponentPopupMenu(popupMenu);

    panelBox.revalidate();

    columnGroupCount++;

    properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount));
}