[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: how to update the shell after invoke setSize()??

I am afraid that is wrong .
I use asyncexec only to ensure the non-UI thread can execute while the
shell is openning.
see this code ,this is the same as before ,but only adds System.out.println("the size of the shell was "+ size);


Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(200,200);
display.asyncExec(new Runnable() {
public void run() {
while(true) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Point size = shell.getSize();
System.out.println("the size of the shell was "+ size);
shell.setSize(size.x+=50,size.y+=50);
}
}
});
shell.open();
while(!shell.isDisposed())
display.readAndDispatch();
display.dispose();
you will see after the shell is openned ,the size of the shell is reported larger and larger ,but the actual size of the shell doesn't change.that means setSize() doesn't work after the shell is openned,except I use the setVisible(false) and setVisible(true) to
update the shell.


Rich Kulp wrote:
You are sleeping in the UI thread, you are not running in another thread. asyncexec does not start a new thread, it runs your runnable in the UI thread. Because you are sleeping in the UI thread, you are locking up the UI for 2 seconds so that nothing happens during that time.