Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT ExpandListener executes before collapse occurs on Linux
SWT ExpandListener executes before collapse occurs on Linux [message #551255] Thu, 05 August 2010 17:53
David Young is currently offline David YoungFriend
Messages: 1
Registered: August 2010
Junior Member
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. It works properly on Mac but does not on Linux.

It looks like the ExpandListener is called before the collapse/expand actually occurs and therefore the pack() resizes incorrectly.

The async execution is merely a bandage to have it work on Mac but this does not work on Linux.

import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.ExpandEvent;
import org.eclipse.swt.events.ExpandListener;

public class ExpandBarExample {
    public static void main(String[] args) {
        Shell shell = new Shell(SWT.DIALOG_TRIM | SWT.MIN
                | SWT.APPLICATION_MODAL);
        shell.setLayout(new FormLayout());
        shell.setText("Expand Bar");
        final ExpandBar bar = new ExpandBar(shell, SWT.NONE);
        FormData fd = new FormData();
        fd.top = new FormAttachment(0);
        fd.left = new FormAttachment(0);
        fd.right = new FormAttachment(100);
        fd.bottom = new FormAttachment(100);
        bar.setLayoutData(fd);

        bar.addExpandListener(new ExpandListener() {

            public void itemCollapsed(ExpandEvent arg0) {
                Display.getCurrent().asyncExec(new Runnable() {
                    public void run() {
                        bar.getShell().pack();
                    }
                });
            }

            public void itemExpanded(ExpandEvent arg0) {
                bar.getShell().pack();

                Display.getCurrent().asyncExec(new Runnable() {
                    public void run() {
                        bar.getShell().pack();
                    }
                });
            }

        });

        Composite composite = new Composite(bar, SWT.NONE);
        fd = new FormData();
        fd.left = new FormAttachment(0);
        fd.right = new FormAttachment(100);
        composite.setLayoutData(fd);

        FormLayout layout = new FormLayout();
        layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 8;

        composite.setLayout(layout);
        Label label = new Label(composite, SWT.NONE);
        label.setText("This is Bar 1");
        ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 0);
        item1.setText("Bar 1");
        item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        item1.setControl(composite);
        item1.setExpanded(true);

        composite = new Composite(bar, SWT.NONE);
        fd = new FormData();
        fd.left = new FormAttachment(0);
        fd.right = new FormAttachment(100);
        composite.setLayoutData(fd);

        layout = new FormLayout();
        layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 8;
        composite.setLayout(layout);
        label = new Label(composite, SWT.NONE);
        label.setText("This is Bar2");
        ExpandItem item2 = new ExpandItem(bar, SWT.NONE, 1);
        item2.setText("Bar 2");
        item2.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        item2.setControl(composite);
        item2.setExpanded(true);

        composite = new Composite(bar, SWT.NONE);
        fd = new FormData();
        fd.left = new FormAttachment(0);
        fd.right = new FormAttachment(100);
        composite.setLayoutData(fd);

        layout = new FormLayout();
        layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 8;
        composite.setLayout(layout);
        label = new Label(composite, SWT.NONE);
        label.setText("This is Bar3");
        ExpandItem item3 = new ExpandItem(bar, SWT.NONE, 2);
        item3.setText("Bar 3");
        item3.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        item3.setControl(composite);
        item3.setExpanded(true);

        bar.setSpacing(6);
        shell.pack();
        shell.open();
        Display display = shell.getDisplay();

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

}

[Updated on: Thu, 05 August 2010 17:53]

Report message to a moderator

Previous Topic:Google buys Instantiations
Next Topic:rich tooltips/managing colors with FormText
Goto Forum:
  


Current Time: Fri Oct 20 20:11:47 GMT 2017

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

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