Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Disposing of a shell when a child shell is disposed
Disposing of a shell when a child shell is disposed [message #455460] Mon, 16 May 2005 00:03 Go to next message
Eclipse UserFriend
Originally posted by: devmike.netcabo.pt

Hi everyone. Can you guy help me out with this?

I have a Shell (s1) which is parent to Shell (s2) which is parent to
Shell (s3).

I'd like s2 to be disposed when s3 is disposed, leaving only s1.

Does someone know how I can achieve this?

What I did was add a DisposeListener to the s3 Shell object in s2 but I
get a stack overflow this way. Why does this happen?

Thanks in advance,
Miguel Barrosa
Re: Disposing of a shell when a child shell is disposed [message #455463 is a reply to message #455460] Mon, 16 May 2005 04:57 Go to previous messageGo to next message
Eclipse UserFriend
Could you please post a snippet ?

Boby

"DevMike" <devmike@netcabo.pt> wrote in message
news:d696ka$ovq$1@news.eclipse.org...
> Hi everyone. Can you guy help me out with this?
>
> I have a Shell (s1) which is parent to Shell (s2) which is parent to
> Shell (s3).
>
> I'd like s2 to be disposed when s3 is disposed, leaving only s1.
>
> Does someone know how I can achieve this?
>
> What I did was add a DisposeListener to the s3 Shell object in s2 but I
> get a stack overflow this way. Why does this happen?
>
> Thanks in advance,
> Miguel Barrosa
Re: Disposing of a shell when a child shell is disposed [message #455466 is a reply to message #455460] Mon, 16 May 2005 09:50 Go to previous messageGo to next message
Eclipse UserFriend
This seems like an swt problem that should be fixed. In the meantime
though, asyncExec'ing the disposal of s2 should work for you, as shown
below:

public static void main(String[] args) {
final Display display = new Display();
Shell s1 = new Shell(display);
s1.setText("s1");
s1.setBounds(10,10,100,100);
final Shell s2 = new Shell(s1);
s2.setText("s2");
s2.setBounds(110,110,100,100);
Shell s3 = new Shell(s2);
s3.setText("s3");
s3.setBounds(210,210,100,100);
s1.open();
s2.open();
s3.open();
s3.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
display.asyncExec(new Runnable() {
public void run() {
s2.dispose();
}
});
}
});
while (!s1.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant

"DevMike" <devmike@netcabo.pt> wrote in message
news:d696ka$ovq$1@news.eclipse.org...
> Hi everyone. Can you guy help me out with this?
>
> I have a Shell (s1) which is parent to Shell (s2) which is parent to
> Shell (s3).
>
> I'd like s2 to be disposed when s3 is disposed, leaving only s1.
>
> Does someone know how I can achieve this?
>
> What I did was add a DisposeListener to the s3 Shell object in s2 but I
> get a stack overflow this way. Why does this happen?
>
> Thanks in advance,
> Miguel Barrosa
Re: Disposing of a shell when a child shell is disposed [message #455699 is a reply to message #455466] Thu, 19 May 2005 13:08 Go to previous message
Eclipse UserFriend
Originally posted by: devmike.netcabo.pt

Hi there Grant. Thanks a lot for your help. Your solution works just the
way I need.

Robert Bacs asked for a code snippet, so here it goes. It's based on the
code Grant provided; I merely changed the widgetDisposed method to a
direct call to s2.dispose():



// running this will cause a stack overflow error

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class closeShells
{
public static void main(String[] args) {
final Display display = new Display();
Shell s1 = new Shell(display);
s1.setText("s1");
s1.setBounds(10,10,100,100);
final Shell s2 = new Shell(s1);
s2.setText("s2");
s2.setBounds(110,110,100,100);
Shell s3 = new Shell(s2);
s3.setText("s3");
s3.setBounds(210,210,100,100);
s1.open();
s2.open();
s3.open();
s3.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e)
{
s2.dispose();
}

});

while (!s1.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}


Grant Gayed wrote:
> This seems like an swt problem that should be fixed. In the meantime
> though, asyncExec'ing the disposal of s2 should work for you, as shown
> below:
>
> public static void main(String[] args) {
> final Display display = new Display();
> Shell s1 = new Shell(display);
> s1.setText("s1");
> s1.setBounds(10,10,100,100);
> final Shell s2 = new Shell(s1);
> s2.setText("s2");
> s2.setBounds(110,110,100,100);
> Shell s3 = new Shell(s2);
> s3.setText("s3");
> s3.setBounds(210,210,100,100);
> s1.open();
> s2.open();
> s3.open();
> s3.addDisposeListener(new DisposeListener() {
> public void widgetDisposed(DisposeEvent e) {
> display.asyncExec(new Runnable() {
> public void run() {
> s2.dispose();
> }
> });
> }
> });
> while (!s1.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> Grant
>
> "DevMike" <devmike@netcabo.pt> wrote in message
> news:d696ka$ovq$1@news.eclipse.org...
>
>>Hi everyone. Can you guy help me out with this?
>>
>>I have a Shell (s1) which is parent to Shell (s2) which is parent to
>>Shell (s3).
>>
>>I'd like s2 to be disposed when s3 is disposed, leaving only s1.
>>
>>Does someone know how I can achieve this?
>>
>>What I did was add a DisposeListener to the s3 Shell object in s2 but I
>>get a stack overflow this way. Why does this happen?
>>
>>Thanks in advance,
>>Miguel Barrosa
>
>
>
Previous Topic:Synchronize Scrolling Question
Next Topic:Another SWT_AWT bridge problems
Goto Forum:
  


Current Time: Sat Jul 19 15:59:50 EDT 2025

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

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

Back to the top