Java Code Examples for javax.swing.JTable#getSelectionModel()

The following examples show how to use javax.swing.JTable#getSelectionModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Remove all selected items from the specified table.
 */
private void handleRemoveAction(JTable theTable) {
    int [] selectedIndices = theTable.getSelectedRows();
    if(selectedIndices.length > 0) {
        ListSelectionModel selectionModel = theTable.getSelectionModel();
        try {
            SRMBaseTableModel theModel = (SRMBaseTableModel) theTable.getModel();
            selectionModel.setValueIsAdjusting(true);
            theModel.removeElements(selectedIndices);
            int numElements = theTable.getModel().getRowCount();
            if(numElements > 0) {
                int newSelectedIndex = selectedIndices[0];
                if(newSelectedIndex >= numElements) {
                    newSelectedIndex = numElements-1;
                }
                selectionModel.setSelectionInterval(newSelectedIndex, newSelectedIndex);
            } else {
                selectionModel.clearSelection();
            }
        } finally {
            selectionModel.setValueIsAdjusting(false);
        }
    }
}
 
Example 2
Source File: PropertySheetTable.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
  JTable table = (JTable)e.getSource();
  if (!table.hasFocus()) {
    CellEditor cellEditor = table.getCellEditor();
    if (cellEditor != null && !cellEditor.stopCellEditing()) { return; }
    table.requestFocus();
    return;
  }
  ListSelectionModel rsm = table.getSelectionModel();
  int anchorRow = rsm.getAnchorSelectionIndex();
  table.editCellAt(anchorRow, PropertySheetTableModel.VALUE_COLUMN);
  Component editorComp = table.getEditorComponent();
  if (editorComp != null) {
    editorComp.requestFocus();
  }
}
 
Example 3
Source File: TubesProjectConfigPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected int getSelectedRow(boolean client) {
    JTable table = client ? tubeTableClient : tubeTableService;
    ListSelectionModel lsm = (ListSelectionModel) table.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        return -1;
    } else {
        return lsm.getMinSelectionIndex();
    }
}
 
Example 4
Source File: KseFrame.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
public void setSelectedEntriesByAliases(String... aliases) {
	JTable jtKeyStore = getActiveKeyStoreTable();
	jtKeyStore.requestFocusInWindow();

	ListSelectionModel selectionModel = jtKeyStore.getSelectionModel();
	selectionModel.clearSelection();
	Set<String> aliasesToSelect = new HashSet<>(Arrays.asList(aliases));
	for (int i = 0; i < jtKeyStore.getRowCount(); i++) {
		if (aliasesToSelect.contains(jtKeyStore.getValueAt(i, 3))) {
			selectionModel.addSelectionInterval(i, i);
		}
	}
}
 
Example 5
Source File: DetailPanel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new <code>DetailPanel</code> instance.
 *
 * @param aTable the table to listen for selections on
 * @param aModel the model backing the table
 */
DetailPanel(JTable aTable, final MyTableModel aModel) {
    mModel = aModel;
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder("Details: "));

    mDetails = new JEditorPane();
    mDetails.setEditable(false);
    mDetails.setContentType("text/html");
    add(new JScrollPane(mDetails), BorderLayout.CENTER);

    final ListSelectionModel rowSM = aTable.getSelectionModel();
    rowSM.addListSelectionListener(this);
}
 
Example 6
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void selectRows(final JTable table, final int[] rows) {
    final ListSelectionModel selectionModel = table.getSelectionModel();
    selectionModel.clearSelection();
    for (int row : rows) {
        selectionModel.addSelectionInterval(row, row);
    }
}