Forums Register Login

Detecting Row Changes on a JTable

+Pie Number of slices to send: Send
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 (https://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!
+Pie Number of slices to send: Send
 

Riaan Nel wrote:I posted this in the General Java forum (https://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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
For future reference, here's the solution that I came up with.

Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 13467 times.
Similar Threads
regarding JTable
JTable switching
jtable
Jtable Cell and ENTER key
Swing Components in Servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:52:08.