Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Being notified when other shell is being closed
Being notified when other shell is being closed [message #554393] Sun, 22 August 2010 19:19 Go to next message
larsk is currently offline larskFriend
Messages: 22
Registered: October 2009
Location: Sweden
Junior Member
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 #554421 is a reply to message #554393] Mon, 23 August 2010 05:38 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 279
Registered: July 2009
Location: India
Senior Member
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,


Lakshmi P Shanmugam
Re: Being notified when other shell is being closed [message #555168 is a reply to message #554421] Wed, 25 August 2010 16:55 Go to previous message
larsk is currently offline larskFriend
Messages: 22
Registered: October 2009
Location: Sweden
Junior Member
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,

Previous Topic:Forcr UI update
Next Topic:Use of Display.addFilter() in practice
Goto Forum:
  


Current Time: Thu Apr 25 08:19:30 GMT 2024

Powered by FUDForum. Page generated in 0.03256 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top