This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: working with JTable

 
Ronnie Knight
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ronnie Knight
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic