Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes problem on JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem on JTable" Watch "problem on JTable" New topic
Author

problem on JTable

Jain Neeraj
Ranch Hand

Joined: Aug 09, 2001
Posts: 35
Hi,
I've a JTable, which saves/retrieve the entered values to the Database. The problem is when i edit a cell and change the value, It's not actually changed as when i'm retireving it, it still shows me the old value..........but if i change the focus from the editing cell to some other cell, It saves the changed value.
in another words if i leave the cursor in the editing cell and hit save, it doesn't actually change and still save the old value.
Any clues on fix for this....
Thanks in advance
-N.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
this is a bug in JDK 1.4.1 which results from the former ((half-)fixed) bug, that the editor stayed in action even when the JTable lost focus. now the Editor is cancelled instead of stopped when the JTable loses focus.
see bug report http://developer.java.sun.com/developer/bugParade/bugs/4503845.html
Jain Neeraj
Ranch Hand

Joined: Aug 09, 2001
Posts: 35
i couldn't get the solution ...Is it fixed? i tried stopCellEditing but that didn't help...
Is there a fix for this problem?
Thanks,
N.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
well, there are some comments on the different bug repords where people have provided some patches but they are all quite "dirty". there is no clean workaround.
if you have the possibility switch back to 1.4.0 (this should be sufficient, I think). you will then need to stop the editor yourself when the table loses focus. but then again, you _can_ stop it.
Jain Neeraj
Ranch Hand

Joined: Aug 09, 2001
Posts: 35
sorry i forgot to mention that i'm using jdk 1.3.1
....
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
sorry, I forgot. there is a workaround suggested by sun (ok, for them it's not a workaround).
catch the lostFocus event for JTable. the event is dispatched before the JTable loses focus (I hope, if not there is certainly another focus event dispatched before the focus is actually transfered). the editor will be active by then. get the value that is displayed by the editor, transfer the focus and set the value in the specific cell to the one you got from the editor.
here is the bug report with the suggestion (see the evaluation field)
http://developer.java.sun.com/developer/bugParade/bugs/4706881.html
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hm, 1.3.1
and stopCellEditing didn't work?
anyway, I paste you this sample code I thought of would work with lesser 1.4.1:

can you check whether the table really is editing (returning isEditing() == true) when you think it is?
Jain Neeraj
Ranch Hand

Joined: Aug 09, 2001
Posts: 35
thank you very much buddy i got it working
 
jQuery in Action, 2nd edition
 
subject: problem on JTable
 
Similar Threads
JTable
Using cell editors in JTable
how to check value of cell in JTable
NX: How to get the new value from the cell of the JTable ?
JTable