This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JTable question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JTable question" Watch "JTable question" New topic
Author

JTable question

Sam Jason
Greenhorn

Joined: Apr 09, 2002
Posts: 6
hi,
I have a question on my GUI design.
I create a JTable to show the requested data, add a new column which allows the user to input the amount of seats he wants to book, and a button to update the data to db.db and refresh the JTable.
The question is : after editing the cell, I have to move the cursor in order to fire the set value method of my table model, and save the data to a vector. if i don't do that(move the cursor) and just click the button, no data would be stored in the vector.
Any suggestion?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
You need to add a JTextBox as the table cell editor, add change listener to the JTextBox and update the Vector. But why?
An easier design would be to provide a JTextBox outside the JTable. User can select a row and enter the seats in the JTextBox which is shown outside the JTable. This is easy compared to the current design and a junior programmer can understand!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

"Sam J"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sam Jason
Greenhorn

Joined: Apr 09, 2002
Posts: 6
hi, sai
thanks for your suggestion, but since JRadioButton coultn't be used in JTable, how could I force the user choice only one row at a time?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Sam,
You can use the JRadioButton in the JTable cell if you use your own renderer.
Can you use the method "setSelectionMode(int selectionMode)" in JTable?
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Originally posted by Sam Jason:
how could I force the user choice only one row at a time?[/QB]

I used this line of code:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTable question