Skip to main content



      Home
Home » Eclipse Projects » JFace » Display Class Dispose method
Display Class Dispose method [message #659664] Tue, 15 March 2011 01:38 Go to next message
Eclipse UserFriend
Hi!!
I have created RenameDialog class by subclassing Dialog class as shown below. (necessary only)

public class RenameDialog extends Dialog{
protected RenameDialog(Shell parentShell) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.SHELL_TRIM);
}

protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText("Rename Dialog");
newShell.setSize(500,150);
}

protected Control createDialogArea(Composite parent)
{}
}


When I am running this using code shown below, on closing of dialog, dialog disappears but disposing of display doesn't happen.

public class RenameDialogTest {

public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display,SWT.BORDER | SWT.TITLE);
RenameDialog dialog=new RenameDialog(shell);
if(dialog.open()==Window.OK)
System.out.println("OK");
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}

display.dispose();
}

}


On above code if I remove, if(!display.readAndDispatch()){..}, it works fine. Could u please explain me the exact funda of this method?

Thanks
Re: Display Class Dispose method [message #659734 is a reply to message #659664] Tue, 15 March 2011 08:08 Go to previous messageGo to next message
Eclipse UserFriend
Your main shell is not disposed. The dialog is show in an extra shell
which is a child of the shell you passed in! You can prove this by
calling shell.open()

Tom

Am 15.03.11 06:38, schrieb Dharam:
> Hi!!
> I have created RenameDialog class by subclassing Dialog class as shown
> below. (necessary only)
>
> public class RenameDialog extends Dialog{
> protected RenameDialog(Shell parentShell) {
> super(parentShell);
> setShellStyle(getShellStyle() | SWT.SHELL_TRIM); }
>
> protected void configureShell(Shell newShell)
> {
> super.configureShell(newShell);
> newShell.setText("Rename Dialog");
> newShell.setSize(500,150);
> }
>
> protected Control createDialogArea(Composite parent)
> {}
> }
>
>
> When I am running this using code shown below, on closing of dialog,
> dialog disappears but disposing of display doesn't happen.
>
> public class RenameDialogTest {
>
> public static void main(String[] args) {
> Display display=new Display();
> Shell shell=new Shell(display,SWT.BORDER | SWT.TITLE);
> RenameDialog dialog=new RenameDialog(shell);
> if(dialog.open()==Window.OK)
> System.out.println("OK");
> while(!shell.isDisposed())
> {
> if(!display.readAndDispatch())
> {
> display.sleep();
> }
> }
>
> display.dispose();
> }
>
> }
>
>
> On above code if I remove, if(!display.readAndDispatch()){..}, it works
> fine. Could u please explain me the exact funda of this method?
>
> Thanks
Re: Display Class Dispose method [message #659743 is a reply to message #659734] Tue, 15 March 2011 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks.

Yes I agree. But main shell has also been created using
new Shell(display).

So why on method call display.dispose() wouldn't deallocate all resources under "display"?
Re: Display Class Dispose method [message #659749 is a reply to message #659743] Tue, 15 March 2011 09:18 Go to previous messageGo to next message
Eclipse UserFriend
You are not getting there you stay in the loop because shell.isDiposed()
is always true and will always be true.

Tom

Am 15.03.11 14:11, schrieb Dharam:
> Thanks.
>
> Yes I agree. But main shell has also been created using
> new Shell(display).
>
> So why on method call display.dispose() wouldn't deallocate all
> resources under "display"?
Re: Display Class Dispose method [message #659766 is a reply to message #659749] Tue, 15 March 2011 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Am 15.03.11 14:18, schrieb Tom Schindl:
> You are not getting there you stay in the loop because shell.isDiposed()
> is always true and will always be true.

Should read ! shell.isDisposed is always true

>
> Tom
>
> Am 15.03.11 14:11, schrieb Dharam:
>> Thanks.
>>
>> Yes I agree. But main shell has also been created using
>> new Shell(display).
>>
>> So why on method call display.dispose() wouldn't deallocate all
>> resources under "display"?
>
Re: Display Class Dispose method [message #659909 is a reply to message #659766] Wed, 16 March 2011 01:22 Go to previous messageGo to next message
Eclipse UserFriend
Thanks.

Hmm you are saying that shell.isDisposed() would return always true in this case,but

->As long as the shell remains open, shell.isDisposed() would return false & it would make while loop condition true

-> This true will allow Display instance to call readAndDispatch() method to keep track of relevant user events in queue.

-> When 1 of this action involves closing of shell, it would make Display to come out of Sleep() & shell.isDisposed() to return true, so as to come out of while loop & call dispose() method.

If I am wrong anywhere, please guide me. Wht should I do in this case then?
Re: Display Class Dispose method [message #659913 is a reply to message #659909] Wed, 16 March 2011 02:18 Go to previous message
Eclipse UserFriend
As you see I corrected my self !shell.isDisposed() == true. If you close
the dialog *the shell of the Dialog is closed* but not the shell you
created in your main()-method.

Could you please add shell.open() before you do a dialog.open() then you
maybe understand what I'm telling you.

Tom

Am 16.03.11 06:22, schrieb Dharam:
> Thanks.
>
> Hmm you are saying that shell.isDisposed() would return always true in
> this case,but
>
> ->As long as the shell remains open, shell.isDisposed() would return
> false & it would make while loop condition true
>
> -> This true will allow Display instance to call readAndDispatch()
> method to keep track of relevant user events in queue.
> -> When 1 of this action involves closing of shell, it would make
> Display to come out of Sleep() & shell.isDisposed() to return true, so
> as to come out of while loop & call dispose() method.
>
> If I am wrong anywhere, please guide me. Wht should I do in this case then?
Previous Topic:Regarding TreeViewer
Next Topic:ComboFieldEditor - setting default selection
Goto Forum:
  


Current Time: Tue Jul 22 23:34:06 EDT 2025

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

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

Back to the top