Example usage for javax.swing JTable changeSelection

List of usage examples for javax.swing JTable changeSelection

Introduction

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

Prototype

public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) 

Source Link

Document

Updates the selection models of the table, depending on the state of the two flags: toggle and extend.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);/*from w w w  .ja  v  a 2s . co m*/

    boolean toggle = true;
    boolean extend = false;
    table.changeSelection(1, 3, toggle, extend);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);// w  ww. java  2  s  .co  m

    int row = 2;
    int col = 1;
    boolean toggle = false;
    boolean extend = false;
    table.changeSelection(row, col, toggle, extend);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);//  w w w .j  a v  a2s  .  c o  m

    int row = 3;
    int col = 2;
    boolean toggle = true;
    boolean extend = false;
    table.changeSelection(row, col, toggle, extend);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);//from   w w  w .j av a2 s .  com

    int row = 5;
    int col = 3;
    boolean toggle = false;
    boolean extend = true;
    table.changeSelection(row, col, toggle, extend);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);//from www .j  av a2 s  .  c om

    int row = 1;
    int col = 3;
    boolean success = table.editCellAt(row, col);
    if (success) {
        boolean toggle = false;
        boolean extend = false;
        table.changeSelection(row, col, toggle, extend);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);

    table.setColumnSelectionAllowed(true);
    table.setRowSelectionAllowed(true);//from   w w  w.j a v a 2 s .  c om

    int row = 1;
    int col = 3;
    boolean success = table.editCellAt(row, col);
    if (success) {
        boolean toggle = false;
        boolean extend = false;
        table.changeSelection(row, col, toggle, extend);
    }
    if (table.getCellEditor() != null) {
        table.getCellEditor().cancelCellEditing();
    }
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java

@Override
public JXTreeTable getTable() {
    if (table == null) {
        if (model == null) {
            model = new HttpFuzzTableModel();
        }/*ww  w. j a v a  2  s  .c o m*/
        table = new JXTreeTable(model);
        table.setDoubleBuffered(true);
        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setName("HttpFuzzResultTable");
        table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        table.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        table.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger()) {
                    if (e.isPopupTrigger()) {
                        // Select list item on right click
                        JTable table = (JTable) e.getSource();
                        int row = table.rowAtPoint(e.getPoint());

                        if (!table.isRowSelected(row)) {
                            table.changeSelection(row, 0, false, false);
                        }
                        View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }

        });
        table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    if (table.getSelectedRowCount() == 0) {
                        return;
                    }
                    final int row = table.getSelectedRow();
                    if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                        final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row))
                                .getHistory();
                        try {
                            getMessageInspection().setMessage(historyReference.getHttpMessage());
                        } catch (HttpMalformedHeaderException | SQLException ex) {
                            logger.error(ex.getMessage(), ex);
                        }
                    }
                    updateValues();
                    redrawDiagrams();
                }
            }
        });
    }
    table.getTableHeader().addMouseListener(new MouseListener() {
        int sortedOn = -1;

        @Override
        public void mouseReleased(MouseEvent arg0) {
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
        }

        @Override
        public void mouseExited(MouseEvent arg0) {
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            int index = table.columnAtPoint(e.getPoint());
            List<HttpFuzzRecord> list = model.getEntries();
            if (list.size() == 0) {
                return;
            }
            HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
            comp.setFeature(index);
            if (index == sortedOn) {
                Collections.sort(list, comp);
                Collections.reverse(list);
                sortedOn = -1;
            } else {
                Collections.sort(list, comp);
                sortedOn = index;
            }
            table.updateUI();
        }
    });
    table.setRootVisible(false);
    table.setVisible(true);
    return table;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java

private <T extends AbstractNamedObject<T>> void addCoreDataObject(final EventList<T> objectsList,
        final T object, final JTable table) {
    checkAndResetActiveCoreDataObject();

    log.debug("Adding a new item...");
    objectsList.add(object);/*w ww .  j av a 2s  .  co m*/
    activeCoreDataObject = object;
    int index = objectsList.size() - 1;

    if (index == -1) {
        index = table.getSelectedRow();
    }
    table.changeSelection(index, 0, false, false);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java

private void setControlDefaults() {

    String[] colName = { "Delays (ps)" };
    int max = 16666;
    try {/* w  w w  .ja  va 2  s.  com*/
        max = Integer.parseInt(core_.getProperty("Laser", "Frequency"));
    } catch (Exception e) {
    }

    tableModel_ = new DelayTableModel(colName, (sap_.getDelaysArray()).get(0), 0, max, 25);
    tableModel_.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            sap_.setDelaysArray(0, tableModel_.getData());
            fm_.setGatingData((sap_.getDelaysArray()).get(0));
            var_.delays = tableModel_.getData();
        }
    });
    delayTable_ = new JTable() {
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component comp = super.prepareRenderer(renderer, row, column);
            int modelRow = convertRowIndexToModel(row);
            int modelColumn = convertColumnIndexToModel(column);
            if (modelColumn != 0 && modelRow != 0) {
                comp.setBackground(Color.GREEN);
            }

            return comp;
        }
    };
    delayTable_.setModel(tableModel_);
    delayTable_.setSurrendersFocusOnKeystroke(true);
    delayTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    JScrollPane scroller = new javax.swing.JScrollPane(delayTable_);
    delayTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(60, 100));
    delayTablePanel.setLayout(new BorderLayout());
    delayTablePanel.add(scroller, BorderLayout.CENTER);

    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete delay");
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = delayTable_.getSelectedRow();
            tableModel_.removeRow(r);
        }
    });
    JMenuItem addItem = new JMenuItem("Add delay");
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = delayTable_.getSelectedRow();
            tableModel_.insertRow(r + 1, 0);
        }
    });
    popupMenu.add(addItem);
    popupMenu.add(deleteItem);
    delayTable_.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            //                System.out.println("pressed");
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                JTable source = (JTable) e.getSource();
                int row = source.rowAtPoint(e.getPoint());
                int column = source.columnAtPoint(e.getPoint());

                if (!source.isRowSelected(row))
                    source.changeSelection(row, column, false, false);

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    // Set up slider controls
    mcpSlider_ = new SliderControl("MCP voltage (V)", 300, 850, 750);
    mcpVoltagePanel.setLayout(new BorderLayout());
    mcpVoltagePanel.add(mcpSlider_, BorderLayout.SOUTH);
    mcpSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            mcpSliderPropertyChange(evt);
        }
    });

    gatewidthSlider_ = new SliderControl("Gate width (ps)", 200, 7000, 3000);
    gatewidthPanel.setLayout(new BorderLayout());
    gatewidthPanel.add(gatewidthSlider_, BorderLayout.SOUTH);
    gatewidthSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            gatewidthSliderPropertyChange(evt);
        }
    });

    HRIControlsPanel.revalidate();
    HRIControlsPanel.repaint();

    slowDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
    slowCurrentDelayPanel.setLayout(new BorderLayout());
    slowCurrentDelayPanel.add(slowDelaySlider_, BorderLayout.SOUTH);
    slowDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            slowDelaySlider_.setValue(tableModel_.validateData(slowDelaySlider_.getValue().intValue()));
            slowDelaySliderPropertyChange(evt);
        }
    });

    fastDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
    fastCurrentDelayPanel.setLayout(new BorderLayout());
    fastCurrentDelayPanel.add(fastDelaySlider_, BorderLayout.SOUTH);
    fastDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            fastDelaySlider_.setValue(tableModel_.validateData(fastDelaySlider_.getValue().intValue()));
            fastDelaySliderPropertyChange(evt);
        }
    });

    delayBoxTabbedPane.revalidate();
    delayBoxTabbedPane.repaint();

    fm_ = new FindMaxpoint();
    maxpointGraphPanel.setLayout(new BorderLayout());
    chartPanel_ = new ChartPanel(fm_.getChart());
    maxpointGraphPanel.add(chartPanel_, BorderLayout.NORTH);
    // for some reason maxpointGraphPanel's height and width are returned 0
    // so hardcode for now...
    chartPanel_.setMaximumDrawWidth(500);
    chartPanel_.setMaximumDrawHeight(200);
    chartPanel_.setPreferredSize(new Dimension(500, 200));

    // Set values for other controls based on underlying data to ensure
    // that all controls are in a consistent state. 
    scanDelCheck.setSelected(sap_.getUseScanFLIM());

}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Show differences./* w ww .  java2 s .co m*/
 */
private void showDifferencesDialog(final Collection<SubjectiveScoreDifference> diffs) {
    final SubjectiveDiffTableModel model = new SubjectiveDiffTableModel(diffs);
    final JTable table = new JTable(model);
    table.setGridColor(Color.BLACK);

    table.addMouseListener(new MouseAdapter() {
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                final JTable target = (JTable) e.getSource();
                final int row = target.getSelectedRow();

                final SubjectiveScoreDifference diff = model.getDiffForRow(row);

                // find correct table
                final String category = diff.getCategory();
                final JTable scoreTable = getTableForTitle(category);
                final int tabIndex = getTabIndexForCategory(category);
                getTabbedPane().setSelectedIndex(tabIndex);

                // get correct row and column
                final SubjectiveTableModel model = (SubjectiveTableModel) scoreTable.getModel();
                final int scoreRow = model.getRowForTeamAndJudge(diff.getTeamNumber(), diff.getJudge());
                final int scoreCol = model.getColForSubcategory(diff.getSubcategory());
                if (scoreRow == -1 || scoreCol == -1) {
                    throw new FLLRuntimeException(
                            "Internal error: Cannot find correct row and column for score difference: " + diff);
                }

                scoreTable.changeSelection(scoreRow, scoreCol, false, false);
            }
        }
    });

    final JDialog dialog = new JDialog(this, false);
    final Container cpane = dialog.getContentPane();
    cpane.setLayout(new BorderLayout());
    final JScrollPane tableScroller = new JScrollPane(table);
    cpane.add(tableScroller, BorderLayout.CENTER);

    dialog.pack();
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setVisible(true);
}