Detecting when a JFrame visibility is set to false.
Hi to all
I currently have the situation where I have a JFrame with a table containing data loaded from a database. Double clicking on a row in the table brings up another JFrame allowing you to edit the data for that row. When you've finished editing the data clicking on okay uploads teh new data to the database and hides the JFrame using
editFrame.setVisible(false)
What I would like to happen is that when the editing frame is hidden the JFrame containing the table should reload the data from the database to reflect the changes made.
To acheive this I've tried both of the following: adding an implementation of WindowListener to the table JFrame and adding a window listener to the editing JFrame so thatin theory when the editing JFrame closes it fires a WindowEvent picked up by
publicvoid windowClosing(WindowEvent e)
which calls the relevant methods to reload the data. But as far as I can tell, setting the JFrame visibility to false does not generate a windows event.
My other alternative was to implement a WindowFocusListener in the table JFrame so that when the editing JFrame closes the table JFrame requests focus, triggering an event picked up by
publicvoid windowGainedFocus(WindowEvent e)
which again would call the relevant methods, but this also didnt work.
I've looked and I can't see any methods to implicitly close a JFrame, so at the moment I'm rather stuck. If anyone's got any suggestions please share :-)
Thanks
[1698 byte] By [
Ruanaea] at [2007-11-26 19:56:59]

# 1
i think you should witer a method say loadDB() in your jframe.
and call it in your constructor.
now after the data Update query has been run u can then simply create a new instance of the frame and dispose the current frame...in the following manner..
new YourJFrame(<parameters>).setVisible(true);
dispose();
please note the above order of statements...
if you call dispose first then you will never reach the next statement
tell me if you like this suggestion
bye
Message was edited by:
vaibhavpingle
# 2
Hmm, that could work, might give it a try. The other possibility would be to pass a reference to the original frame into the editing frame and then call the methods directly. But while that would work in the current situation where the editing frame is only ever used by this particular table frame I do have a situation where I have a editing frame that can be called in lots of different places so it would require checking what the orginating frame is and loading the correct methods. Some how, using events to detect when the frame is "closed" seems cleaner. At least to me anyway.
I've managed to get it working using the window focus listener (helps if you call the correct methods in your event handler :-S) but would still like to see if there's a more effective solution as, currently this means the data will be reloaded EVERY time the JFrame gets focus which could be quite expensive.
Thanks
Message was edited by:
Ruanae
Message was edited by:
Ruanae
# 8
the data u say is availableis in the database........and for getting it...u need to access it.....
Eh?
From the OP: "I have a JFrame with a table containing data loaded from a database. Double clicking on a row in the table brings up another JFrame allowing you to edit the data for that row."
We're talking about closing the second window, the editing frame. The first window is still there and behind the model of that table must be all the data that's been fished out of the database - typically you'd have an object for each row.
So you have the data. It's in the original table model, or a structure which is wrapped by it.
So there's no need to go back to the database.