This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: How to get the new value from the cell of the JTable ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: How to get the new value from the cell of the JTable ?" Watch "NX: How to get the new value from the cell of the JTable ?" New topic
Author

NX: How to get the new value from the cell of the JTable ?

kwwong wong
Ranch Hand

Joined: Feb 15, 2002
Posts: 56
How to get the new value from the cell of the JTable ?
When I editing the cell in JTable, i.e. change the owner field, and then click the "book" button to save the record, it cannot retrieve the new value of the owner. When I use the getValueAt method it gives me the old value! It seems that the JTable do not trigger the setValueAt method.
However, when I left the row I am editing to another row (at this time the JTable trigger the setValueAt method) and then reselect the editing row. At this time, when I click the "book" button, the new value is saved to the database.
How to solve this problem ?
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
In your setValueAt mehtod, are you updating both the table model and the database? Only doing one or the other might cause what you describe.
ms


ms<br />SCJP, SCJD
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
One question is why do you have a book button. I just let the JTable handle the update of both the database and the table model for me. Now that I think about it, having a book button forces you to do the database update outside of your table model. I'd just verify that your setValueAt method is being called (just use System.out.println if you don't have a debugger) and make sure it updates the table model properly (use getValueAt).
ms
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Unless they are requiring you to have th changes be made in the JTable directly. I think the better approach is to have the JTable be read-only. And have a JTextField and a Book JButton just below it to allow the user to enter the data. Obviously the data entered will be in correlation with the row that is selected in the JTable.
This was my approach, I received 100% on GUI, so I know that I didn't lose points for that design.
As with everything in the assignment, your design is completely your decision. So you can choose how the user books any way you want. At least make sure that it is user friendly/ follows basic GUI standards and operates correctly.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
kwwong wong
Ranch Hand

Joined: Feb 15, 2002
Posts: 56
I found that the setValueAt is not trigger in JTable if I have not made the cursor leaving from current editing cell to another cell in JTable. So I cannot retrieve the new owner when I click the book button if the cursor is on the record's "owner" cell.
I have followed Mark Spritzler and it works fine. Thanks.
Davidd Smith
Ranch Hand

Joined: Jul 28, 2003
Posts: 62
Hi mark,
You did well on GUI, I hava a guestion.
I also make the Table read only and I put a input panel with a find button on top of it for user to type in find criteria. My input panel contains every field of the record so that user can find based on whatever combination of conditions. My question is: Should I get the fields from the Data class to build my JLabels and JTextFields and tableHeader or I only hard code it in the GUI? In the former case, I can only use the JTextField and can not provide JComboBox or JCheckBox which will make the GUI friendly and reduce input error, meanwhile, the JLabel and JtableHeader's content must be the fields' name which may be not clear. In the former case, if the schema of database is changed, we must re-write the GUI, so the mantainability is bad.
What is your suggest? I am looking forward it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: How to get the new value from the cell of the JTable ?
 
Similar Threads
JTable Editing
Checkbox editor for JTable column
JTable problem
NX: Update owner in JTable
JTable Trouble