JTable single row selection

Anna Hays

Ranch Hand

Posts: 131

posted 12 years ago

Hi, can anyone tell me if it is possible to allow a single row selection please? I want them to select one single row at any one time to ensure 1 record booking. Multiple selection can be misleading. I have been looking throught APIs and can't find anything useful. Thanks for any help/suggestion.

peter wooster

Ranch Hand

Posts: 1033

posted 12 years ago

Originally posted by Marlene Miller: Hi Anna,

The Java Swing Tutorial describes how to specify that only one row at a time can be selected. Here is how I navigated through the Tutorial to find the section:

Since I have the book and a marker on the JTable section, I just flipped through the pages. It's easier to find that way .

Regards, Marlene

[ October 09, 2004: Message edited by: Marlene Miller ]

I know the search is more than half the fun, but late on a Saturday night

does the trick.

Anna Hays

Ranch Hand

Posts: 131

posted 12 years ago

Thank you! It is working. I have chosen the wrong mode before. D'oh!

Another question, about ListSelectionLister registered for a JTable. The valueChanged action is triggered twice when a selection is made, one for pressing and the other for releasing the mouse button. Why is that? How can I make it only trigger once for any changed selection?

Anna Hays

Ranch Hand

Posts: 131

posted 12 years ago

This is the line if anyone is interested.

Anton Golovin

Ranch Hand

Posts: 527

1

posted 12 years ago

Originally posted by Anna Kafei: Hi, can anyone tell me if it is possible to allow a single row selection please? I want them to select one single row at any one time to ensure 1 record booking. Multiple selection can be misleading. I have been looking throught APIs and can't find anything useful. Thanks for any help/suggestion.

Hi, Anna. In addition to single selection, I found that my JTable allowed ths user to edit text in its cells. To get rid of this behavior I had to overwrite the AbstractTableModel and there to overwrite the isCellEditable(int, int) method to always return false.

Sorry if this is not helpful. It was helpful to me in the general sum of questions related to the JTable functioning.