Forums Register Login

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

+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1209 times.
Similar Threads
Checkbox editor for JTable column
JTable Trouble
JTable problem
JTable Editing
NX: Update owner in JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:48:36.