Reputation: 231
I am trying to display scrollable composite in my dialog window.
But it do not get the scrollbars. I also don't get the "OK" "Cancel" buttons.
How to fix it?
public class MyDialog extends Dialog {
public MyDialog (Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("test");
newShell.setSize(200, 100);
}
protected Control createDialogArea(Composite parent) {
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Label(composite, SWT.NONE).setText("1111");
new Label(composite, SWT.NONE).setText("2222");
new Label(composite, SWT.NONE).setText("3333");
new Label(composite, SWT.NONE).setText("4444");
new Label(composite, SWT.NONE).setText("5555");
new Label(composite, SWT.NONE).setText("6666");
new Label(composite, SWT.NONE).setText("7777");
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
return parent;
}
Upvotes: 1
Views: 3228
Reputation: 36894
Ok, so I almost got it working. However, at the bottom there is some empty space where the dialog buttons would be. If this doesn't bother you, or you are going to add buttons, the code below will do what you want. If not, I don't know how to help you.
public class MyDialog extends Dialog
{
protected MyDialog(Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("test");
newShell.setSize(200, 100);
}
protected void createButtonsForButtonBar(Composite parent) {
}
protected Control createDialogArea(Composite parent) {
Composite content = (Composite) super.createDialogArea(parent);
content.setLayout(new FillLayout());
ScrolledComposite sc = new ScrolledComposite(content, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);
Composite composite = new Composite(sc, SWT.NONE);
composite.setLayout(new FillLayout(SWT.VERTICAL));
new Label(composite, SWT.NONE).setText("1111");
new Label(composite, SWT.NONE).setText("2222");
new Label(composite, SWT.NONE).setText("3333");
new Label(composite, SWT.NONE).setText("4444");
new Label(composite, SWT.NONE).setText("5555");
new Label(composite, SWT.NONE).setText("6666");
new Label(composite, SWT.NONE).setText("7777");
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return parent;
}
}
However, I assume you are going to use dialog buttons. Otherwise you could simply use a shell with a composite as seen in the example I posted before...
Upvotes: 1