Is there a Java WindowListener that gets called just before a Window is shown?
I’ve tried both windowOpened (example below) and componentShown. Both of these get called just after the window is shown. Is there any listener that gets called before the window is shown?
window.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent evt) {
< ... code ... >
}
});
As you wish here’s an answer compiled by the comments.(Maybe sometimes somebody will search for that 😉 )
The solution here may to override your
JFrame‘ssetVisible(boolean)-method by subclassingJFrame.That method could look like this:
As in this case you need to refactor your code to use the new subclass, just find and replace every “new JFrame” to “new YourFrameSub”(every editor or IDE should be able to do that).
This way you can ensure your code is executed, before anything is shown.
Remember to use a
SwingWorkeror sth. like that to show something like aProgressBarin aJDialogto show the user that something will take longer than expected. Of course this only takes place if you’re planning to execute a long running action like doing IO-operations.