|
Java™ by example!
|
|
|
How do I allow only individual rows to be selected in a JTable?
By default, multiple rows can be selected in a Table. You can change this behavior through a ListSelectionModel. Invoke the method setSelectionMode on your JTable object and set it to one of these three static final variables defined in ListSelectionModel: MULTIPLE_INTERVAL_SELECTION: to allow multiple contiguous selection ranges SINGLE_INTERVAL_SELECTION: to allow one contiguous selection range SINGLE_SELECTION: to allow only one list index selection Add a ListSelectionListener and define the behaviour in valueChanged. Here's a working example:
Further Information
Author of answer: Joris Van den Bogaert
Comments
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|