The list of methods to do JTable Select are organized into topic(s).
void
copyTableSelectionsToJList(JList list, JTable listTbl) Synchronisiert eine JList mit einem JTable.
list.setSelectedIndices(new int[0]);
int rows = listTbl.getRowCount();
Vector sel = new Vector();
for (int i = 0; i < rows; i++) {
if (listTbl.getSelectionModel().isSelectedIndex(i)) {
sel.add(new Integer(listTbl.convertRowIndexToModel(i)));
int tmp[] = new int[sel.size()];
for (int i = 0; i < sel.size(); i++)
tmp[i] = ((Integer) sel.get(i)).intValue();
list.setSelectedIndices(tmp);
JCheckBox
createJCheckBoxForTable(boolean selected) It creates a new check box for inclusion in a table and sets its "is selected" attribute to the given value.
JCheckBox checkBox = new JCheckBox();
checkBox.setOpaque(true);
checkBox.setHorizontalAlignment(SwingConstants.CENTER);
checkBox.setForeground(TABLE_COMPONENT_FG_COLOR);
checkBox.setBackground(TABLE_COMPONENT_BG_COLOR);
checkBox.setSelected(selected);
return checkBox;
void
disableSelection(JTable table) Disable any selections on a table.
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
table.setCellSelectionEnabled(false);
table.setFocusable(false);
Integer
getSelectedCase(JTable table) get Selected Case
int selectedRow = table.getSelectedRow();
if (selectedRow >= 0) {
return (int) table.getModel().getValueAt(selectedRow, 0);
} else {
return null;
Integer[]
getSelectedObject(JTable table) get Selected Object
Integer[] selected = new Integer[2];
int selectedRow = table.getSelectedRow();
if (selectedRow >= 0) {
selected[0] = (int) table.getModel().getValueAt(selectedRow, 0);
selected[1] = (int) table.getModel().getValueAt(selectedRow, 1);
return selected;
} else {
return null;
...
void
invertSelect(JTable table) invert Select
int[] temp = table.getSelectedRows();
ArrayList<Integer> selectedRows = new ArrayList<Integer>();
for (int index = 0; index < temp.length; index++) {
selectedRows.add(temp[index]);
ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.clearSelection();
for (int index = 0; index < table.getRowCount(); index++) {
...
void
invertSelection(JTable table) invert Selection
for (int rowCount = table.getRowCount() - 1; rowCount >= 0; rowCount--) {
if (table.isRowSelected(rowCount)) {
table.removeRowSelectionInterval(rowCount, rowCount);
} else {
table.addRowSelectionInterval(rowCount, rowCount);
void
moveSelectionDown(JTable table) move Selection Down
int selectedRow = table.getSelectedRow();
int selectedRowCount = table.getSelectedRowCount();
int rowCount = table.getRowCount();
int targetRow;
if (rowCount == 0) {
return;
} else if (rowCount == 1) {
targetRow = 0;
...