Search code examples
javasqlswingjtablewindowlistener

Update JTable as a window closes


Good afternoon!

I have a main program (let's call it window1) that displays a JTable and is populated by data in an SQL database. When you double click on the JTable it opens up a new window (let's call it window2) that allows the user to edit the database.

I would like to add a windowListener to window2 so that as it closes, it tells window1 to repopulate the JTable contained there.

I tried looking around at window events and attempted to figure out how to use them, but I'm just not understanding it... If you need certain parts of my code, feel free to ask.

I have a method in my main program that initially updates the JTable when window1 is loaded, but need to figure out how to call that method when window2 closes.

Thanks in advance!


Solution

  • What exactly do you have in window2? Any confirmation button maybe? If so, then you could call the JTable's update method inside the listener for that button.