Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable single row selection

 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the line if anyone is interested.
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. No need to be sorry. It is great to share knowledge.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic