Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting ScrolledComposite to scroll

55 views
Skip to first unread message

lio...@gmail.com

unread,
Feb 14, 2007, 2:02:34 AM2/14/07
to
I'm new to SWT, I have come from using Swing.

I think I'm having problems with the size stuff but I'm not sure.
Basically I've forced the scroll bar to show, but it's not enabled.
Here's my code as a subclass of org.eclipse.jface.window.Window:

protected Control createContents(Composite parent) {
//layout the parent composite
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 2;
parent.setLayout(layout);

ScrolledComposite scrolledComposite = new
ScrolledComposite(parent,
SWT.V_SCROLL | SWT.BORDER);
scrolledComposite.setAlwaysShowScrollBars(true);

//layout the composite holding the content
content = new Composite(scrolledComposite, SWT.BORDER);
scrolledComposite.setContent(content);
content.setLayout(new GridLayout(2, false));
content.setLayoutData(new GridData(GridData.FILL_BOTH));

//heading font
FontData fontData = new FontData();
fontData.setStyle(SWT.BOLD);
Font font = new Font(Display.getCurrent(), fontData);

//create the heading labels
Label label = new Label(content, SWT.CENTER);
label.setText("Variable Name");
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
label.setFont(font);

label = new Label(content, SWT.NULL);
label.setText("Hide Variable?");
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
label.setFont(font);

//adds 0-many labels to content
addVariablePairs();

content.setSize(content.computeSize(SWT.DEFAULT,
SWT.DEFAULT));
content.layout(true);
return parent;
}

Thanks

Lionel.

lio...@gmail.com

unread,
Feb 14, 2007, 2:14:38 AM2/14/07
to
SOLUTION:

Set the layout of the parent to FillLayout and it works.

thanks

Lionel.

0 new messages