Enabling Single or Multiple Selections in a JTable Component

By default, a table component allows multiple selections. To control the selection behavior, see Enabling Row, Column, or Cell Selections in a JTable Component.
JTable table = new JTable(); // Get default selection mode int selMode = table.getSelectionModel().getSelectionMode(); // MULTIPLE_INTERVAL_SELECTION // Allow only single a selection table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Allow selection to span one contiguous set of rows, // visible columns, or block of cells table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); // Allow multiple selections of rows, visible columns, or cell blocks (default) table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.