[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: ScrolledComposite problem

Thanks Leo,

that change you suggested worked great.

John.
Try adding the line...

aScrolledComposite.setMinSize(aInnerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

right before your shell.open().

 - Leo

John Carroll wrote:
Hello,

I am trying to display a number of Labels within 3 columns in a ScrolledComposite but I cannot get the scrolling to work, here is my code :

public static void main(String[] args)
    {

        Display display = new Display ();
        Shell shell = new Shell (display);
        shell.setLayout(new GridLayout());

        ScrolledComposite aScrolledComposite = new ScrolledComposite(
                shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

aScrolledComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));

aScrolledComposite.setExpandHorizontal(true);
aScrolledComposite.setExpandVertical(true);
aScrolledComposite.setAlwaysShowScrollBars(true);
aScrolledComposite.setBackground(shell.getDisplay().getSystemColor(
SWT.COLOR_WHITE));
aScrolledComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));


Composite aInnerComposite = new Composite(aScrolledComposite, SWT.NONE);

aInnerComposite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));

        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 3;
        aInnerComposite.setLayout(gridLayout);
        aInnerComposite.setBackground(shell.getDisplay().getSystemColor(
                SWT.COLOR_WHITE));
        aScrolledComposite.setContent(aInnerComposite);

final Label typeLabel = new Label(aInnerComposite, SWT.NONE);
final GridData gd_typeLabel = new GridData(SWT.FILL, SWT.CENTER, true, false);
typeLabel.setLayoutData(gd_typeLabel);
typeLabel.setText("Type");


final Label nameLabel = new Label(aInnerComposite, SWT.NONE);
nameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
nameLabel.setText("Name");


final Label textLabel = new Label(aInnerComposite, SWT.NONE);
final GridData gd_textLabel = new GridData(SWT.LEFT, SWT.CENTER, true, false);
textLabel.setLayoutData(gd_textLabel);
textLabel.setText("Text");


        for(int aI = 0;aI < 100;aI++)
        {
            AddLine(aInnerComposite, (aI+1));
        }



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

private static void AddLine(Composite aParent, int aCount)
{
final Label typeLabel = new Label(aParent, SWT.NONE);
final GridData gd_typeLabel = new GridData(SWT.FILL, SWT.CENTER, true, false);
typeLabel.setLayoutData(gd_typeLabel);
typeLabel.setText("Type " + aCount);


final Label nameLabel = new Label(aParent, SWT.NONE);
nameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
nameLabel.setText("Name " + aCount);


final Label textLabel = new Label(aParent, SWT.NONE);
final GridData gd_textLabel = new GridData(SWT.LEFT, SWT.CENTER, true, false);
textLabel.setLayoutData(gd_textLabel);
textLabel.setText("Text " + aCount);
}





thanks for any help you can offer.

John.