Forums Register Login

JTable single row selection

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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:

http://java.sun.com/docs/books/tutorial/uiswing/index.html
The Java Swing Tutorial

http://java.sun.com/docs/books/tutorial/uiswing/components/index.html
Using Swing Components

http://java.sun.com/docs/books/tutorial/uiswing/components/componentlist.html
How To�

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
How To Use Tables

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#selection
Detecting User Selections

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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send


This is the line if anyone is interested.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Thanks. No need to be sorry. It is great to share knowledge.
It runs on an internal combustion engine. This ad does not:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 13291 times.
Similar Threads
JTable selection listener doesn't listen to column changes
JComboBox in the JTable Editor
function for radio button
JTable Selection Depends On Editable Cells
Rich faces extendedDataTable question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:05:53.