Renato Dinhani
Renato Dinhani

Reputation: 36696

How to trigger an event when another window is closed?

I have a button that open a new window to the user do some configurations. After the configuration window is closed, I want to reload the configurations in the window that called the configuration window.

How I do this?

Upvotes: 2

Views: 754

Answers (3)

Charles Goodwin
Charles Goodwin

Reputation: 6642

You need to implement a WindowListener. See how to write Window Listeners.

WindowAdapter myListener = new WindowAdapter() {
    // maybe you want windowClosing
    public void windowClosed(WindowEvent e) {
        // actions to perform after window is closed
    }
}
// add to a Window (JFrame is a subclass of Window)
myWindow.addWindowListener(this);

Upvotes: 1

Jerry Gagnon
Jerry Gagnon

Reputation: 1161

As long as the form isn't freed on close you can still access the variable representing the form and get its properties and control values.

EDIT: Ok, I'm a little confused, but let's try this again. There are MANY ways in which you can solve this problem.

The easiest way is to simply call the configuration form with ShowModal and then process the configuration information within the button's click event once the form is closed.

Another way is to have the configuration form store its values in an allocated object (a TStringList, for instance) and then send the reference to that object via a message to the main form in the OnClose of the configuration form. Your main form would then use the TStringList to get all the configuration information and then free it. Again, this is only one way of many this can be done.

So much depends on how you want this all to work.

Upvotes: 3

camickr
camickr

Reputation: 324128

Use a modal dialog for your configuration window. Then when the dialog is closed execution of the code will continue after your statement that displayed the configuration window so you can reload the properties.

Upvotes: 4

Related Questions