This is a simple executable snippet that shows the issue.
When using the ExpandBar the desired outcome is to resize the window when there is a collapse or expand.
This is an old post but I recently had this problem, and found this solution helphul.
However, I find that it is only necessary to call shell.pack() from another thread (via syncExec of course). I never have to go through loop. So I ctreated this little subroutine:
private void async_shell_pack(final Display display, final ExpandBar bar) {
new Thread(new Runnable(){
public void run(){
display.syncExec(new Runnable() {
public void run() {
bar.getShell().pack(true);
}
});
}}).start();
}
This seems to work fine. For my purposes, better still, was to simply grow the height of the shell by the height of the expanded item using the following listener.
public void itemExpanded(ExpandEvent e) {
if (e.item instanceof ExpandItem){
ExpandItem item = (ExpandItem)e.item;
shell.setSize(shell.getSize().x, shell.getSize().y+item.getHeight());
} else {
System.out.println("Boom");
}
}
This means no messing about with threads.