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:  working with 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:  working with JTable" Watch "NX:  working with JTable" New topic
Author

NX: working with JTable

Ronnie Knight
Greenhorn

Joined: Oct 28, 2003
Posts: 3
Is there any type of Listener that will notify me that a user has selected
a different row...before the JTable changes the value of the original cell and updates the underlying model?
Basically, if someone edits a cell and then decides to click on another row,
I want to popup a confirmation dialog to confirm or cancel the edit that they just performed. If yes then allow the model to be updated if no then
cancel the edit.
I have tried to use the ListSelectionListener but the model always updates
by the time that I have been notified that a different row has been selected.
Thanks!
Ron.
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
Have you tried java.sun.com? There is a swing tutorial which extensively
covers the JTable, and probably could answer this specific question.
I am not sure, though, why you want the cells in your JTable to be editable?
I would recommend against this unless your specifications require it in
some manner that I am not aware of.
Thanks,
Javini Javono
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
What it seems to me that you might really want is to popup the confirmation dialog when the user tries to complete a prospective edit, not necessarily just when selecting another row. If that is what you want, you can add a CellEditorListener to the CellEditor(s) of interest. When the user attempts to complete the edit, the CellEditorListener can popup your confirmation dialog. You probably would have to do this for each cell in each row or use a ListSelectionEditor to add/remove the CellEditorListener(s) as needed whenever the row selection is changed.


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Ronnie Knight
Greenhorn

Joined: Oct 28, 2003
Posts: 3
(Sorry for not mentioning this before: I am working on B&S 2.1.2)
Ken:
Yep...something like that is what I had in mind...I'll give it a try.
Javini:
I was thinking that I would have all cells not editable except for the owner id field for each contract, and then only if it was blank. The user could just type in an owner id and hit enter to stop editing. As long as I have a TableModelListener registered with my data model, the listener can instruct my controller to persist the data to the database.
However, if the user edits an owner id field and then tries to select a different row without hitting the enter key first, I need to make sure that the info that they entered was exactly what they wanted because after an owner id has been assigned, I make the owner id field of that row
non-editable.
Maybe it is a bit of overkill, but it seems that further enhancements to the client would be easier to make doing things this way. All you would have to do to update any of the fields is just make them editable.
What do you think?
Ronnie Knight
Greenhorn

Joined: Oct 28, 2003
Posts: 3
I hope that neither of you all took my signature personally...I have been working on it lately, and I forgot to de-select the checkbox before I replied.
Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
I don't have enough information about your project to offer an opinion
(and I wouldn't want to offer an opinion while having, at best, partial project
requirements information).
Perhaps others can be of more service to you on this particular matter
either because they had that particular project or because they've been
associated with this group longer, and no all your project's details.
Good luck,
Javini Javono
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: working with JTable
 
Similar Threads
JTable
JTable
JTable and animation refreshing problem
JTable
JTable Cell Editor