Reputation: 809
I have a dialog box with the below code. The scroll bar appears, but does not scroll till the end. It is too long that the contents in the end do not come up. Even if the dialog is re-sized to be small, the contents towards the end cannot be seen. Please suggest how to get the scroll bar working right for the below scenario.
public class SampleDialog extends TrayDialog {
public SampleDialog(final Shell shell) {
super(shell);
this.shell = shell;
}
@Override
public void create() {
super.create();
}
@Override
protected Control createDialogArea(final Composite parent) {
final GridLayout layout = new GridLayout();
layout.numColumns = 1;
parent.setLayout(layout);
final ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
sc1.setExpandHorizontal(true);
sc1.setExpandVertical(true);
//sc1.setMinWidth(0);
final Composite composite = new Composite(sc1, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
sc1.setContent(composite);
//this.sc1.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
//this.sc1.setMinHeight(50);
//this.sc1.setAlwaysShowScrollBars(true);
sc1.addControlListener(new ControlAdapter() {
@Override
public void controlResized(final ControlEvent e) {
final Rectangle r = sc1.getClientArea();
sc1.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
}
});
final GridData gridDataLabel = new GridData();
final Label label = new Label(composite, SWT.NONE);
label.setText("Testing");
label.setLayoutData(gridDataLabel);
for (i = 0 ; i <= n ; i++) { // n can be 1 to any number -- decided at run time
createSampleCombo(composite);
}
}
public void createSampleCombo(Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.numColumns = 3;
composite.setLayout(layout);
final GridData gridDataCombo = new GridData();
gridDataCombo.horizontalAlignment = GridData.FILL;
gridDataCombo.grabExcessHorizontalSpace = true;
final Combo myCombo = new Combo(composite, SWT.NONE);
myCombo.setLayoutData(gridDataCombo);
gridDataCombo.minimumWidth = 500;
final GridData gridDataButton = new GridData();
final Button browse = new Button(composite, SWT.PUSH);
browse.setText("Browse");
browse.setLayoutData(gridDataButton);
}
}
where:
org.eclipse.jface.dialogs.TrayDialog;
org.eclipse.swt.layout.GridLayout;
in the 3rd image, the last control is not visible and the ok and cancel button are also not visible. I need the scroll bar to go down so that i can see all the contents. Please suggest how this can be done
Upvotes: 2
Views: 719
Reputation: 21025
I had a similar problem just recently and I solved it this way: First you should prevent the ScrolledComposite from expanding vertically:
sc1.setExpandVertical( false );
If you then change the resizeListener to:
Rectangle clientArea = scrolledComposite.getClientArea();
Point minSize = scrolledComposite.getContent().computeSize( clientArea.width, SWT.DEFAULT );
scrolledComposite.getContent().setSize( minSize );
the ScrolledComposite should only take the space that it is permitted from the layout of its container.
More on how to use ScrolledComposites can be found here: http://www.codeaffine.com/2016/03/01/swt-scrolledcomposite/
Upvotes: 1