javax.swing.JTable#getSelectionModel ( )源码实例Demo

下面列出了javax.swing.JTable#getSelectionModel ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** 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);
        }
    }
}
 
源代码2 项目: CodenameOne   文件: PropertySheetTable.java
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();
  }
}
 
源代码3 项目: netbeans   文件: TubesProjectConfigPanel.java
protected int getSelectedRow(boolean client) {
    JTable table = client ? tubeTableClient : tubeTableService;
    ListSelectionModel lsm = (ListSelectionModel) table.getSelectionModel();
    if (lsm.isSelectionEmpty()) {
        return -1;
    } else {
        return lsm.getMinSelectionIndex();
    }
}
 
源代码4 项目: keystore-explorer   文件: KseFrame.java
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);
		}
	}
}
 
源代码5 项目: cacheonix-core   文件: DetailPanel.java
/**
 * 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);
}
 
源代码6 项目: snap-desktop   文件: MosaicExpressionsPanel.java
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);
    }
}
 
 方法所在类
 同类方法