Display Class Dispose method [message #659664] |
Tue, 15 March 2011 01:38  |
Eclipse User |
|
|
|
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 #659913 is a reply to message #659909] |
Wed, 16 March 2011 02:18  |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.03833 seconds