Being notified when other shell is being closed [message #554393] |
Sun, 22 August 2010 15:19  |
Eclipse User |
|
|
|
I have written a test application where I want to know when the second shell is being closed.
The application starts with MainShell from where I can open SecondShell. Is there any way that I from MainShell can be notified when SecondShell is being closed?
Code from the file MainShell.java:
package swtshelltest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
public class MainShell extends Shell
{
Button buttonOpen = new Button(this, SWT.NONE);
public static void main(String[] args)
{
MainShell main = new MainShell();
}
MainShell()
{
super(Display.getDefault(), SWT.CLOSE);
this.setText("MainShell");
this.setBounds(100, 100, 200, 200);
buttonOpen.setText("Open");
buttonOpen.setLocation(10, 10);
buttonOpen.pack();
buttonOpen.addSelectionListener(openSecondShell);
this.open();
while (!this.isDisposed())
{
if (!Display.getDefault().readAndDispatch())
Display.getDefault().sleep();
}
}
@Override
protected void checkSubclass()
{
}
//funktion som körs när man klickar på knappen som startar resultatvisningen
SelectionListener openSecondShell = new SelectionListener()
{
@Override
public void widgetSelected(SelectionEvent event)
{
SecondShell secondShell = new SecondShell();
}
@Override
public void widgetDefaultSelected(SelectionEvent event)
{
}
};
}
Code from the file SecondShell.java:
package swtshelltest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SecondShell extends Shell
{
SecondShell()
{
super(Display.getDefault(), SWT.CLOSE);
this.setText("SecondShell");
this.setBounds(400, 100, 100, 100);
this.open();
}
@Override
protected void checkSubclass()
{
}
}
|
|
|
|
Re: Being notified when other shell is being closed [message #555168 is a reply to message #554421] |
Wed, 25 August 2010 12:55  |
Eclipse User |
|
|
|
Ok, it was that easy.
Thanks!!!
Lakshmi Shanmugam wrote on Mon, 23 August 2010 07:38 | Hi,
You can add the ShellListener to your shell as shown here:
SecondShell secondShell = new SecondShell();
secondShell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
System.out.println("second shell closed");
};
});
In general, when you want to be notified about the state changes on the Shell (such as shell closed, shell activated/deactivated, shell iconified/deiconified) you can use the ShellListener.
HTH,
|
|
|
|
Powered by
FUDForum. Page generated in 0.03017 seconds