Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting Row Changes on a JTable  RSS feed

 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning Everybody

I have a scenario where I have a JTable in which the user is allowed to make changes. When the user changes the selected row, I would like to pop up a confirmation prompt before saving any changes to a row. I've tried a ListSelectionListener, but it causes the UI to be 'frozen' between two selected rows when the prompt comes up. Is there any way in which I can get a listener on a JTable to fire before the row is actually changed? I posted this in the General Java forum (http://www.coderanch.com/t/535665/java/java/Detecting-Row-Changes-JTable) as well, as I did not realize that JavaRanch has a Swing/AWT/SWT/JFace forum.

Here's a simplified example.



Thanks for your help!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riaan Nel wrote:I posted this in the General Java forum (http://www.coderanch.com/t/535665/java/java/Detecting-Row-Changes-JTable) as well, as I did not realize that JavaRanch has a Swing/AWT/SWT/JFace forum.


Thanks for linking the duplicate thread. I've removed it.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's my attempt to solve your problem with a class extending JTable and overriding valueChanged().I can't see any LaF independent way to prevent the clicked cell from appearing selected before the dialog is shown.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look in the Oracle's JTable tutorial and how to use models. You need a model that just doesn't change if it shouldn't. No need to tamper with the presentation.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

Darryl, thank you for your solution - I'll play with it a bit when I get back to working on the app.

Hauke, thanks for the link and the hint, I'll go through it and see if I can get my table model to behave the way I want.

Regards,
Riaan
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For future reference, here's the solution that I came up with.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!