[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: Refresh in swt

It seems that it doesn't work.
thanks for your help!
Pr.


Veronika Irvine wrote:

Can you make the following example fail in the same way:

public class Main {
public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER |SWT.V_SCROLL
|  SWT.H_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    Composite c1 = new Composite(sc, SWT.NONE);
    sc.setContent(c1);
    c1.setLayout(new GridLayout());
    Composite c2 = new Composite(c1, SWT.BORDER);
    c2.setLayout(new FillLayout());
    Composite c3 = new Composite(c2, SWT.BORDER);
    c3.setLayout(new GridLayout());
    Button b = new Button(c3, SWT.PUSH);
    b.setText("button 1");
    b = new Button(c3, SWT.PUSH);
    b.setText("button 2");
    final int[] index = new int[]{3};
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button)e.widget;
            Composite parent = b.getParent();
            Button b2 = new Button(parent, SWT.PUSH);
            b2.setText("button "+index[0]);
            index[0]++;
            Control c = b;
            while (parent != null) {
                if (parent instanceof ScrolledComposite) {
                    if (c instanceof Composite) {
                        ((Composite)c).layout();
                    }

((ScrolledComposite)parent).setMinSize(c.computeSize(SWT.DEFAULT,SWT.DEFAULT));
                    break;
                } else {
                    c = parent;
                    parent = parent.getParent();
                }
            }
        }
    });

    sc.setMinSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    shell.pack();
    shell.open();

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

Priscille de Peslouan wrote:

> > Do you have a GridLayout on all your children composites or do you sometimes
> > have a FillLayout or a FormLayout?
>
> I have a GridLayout on most of my children composites but sometimes I have a
> FillLayout.
> Pr.