Setting the Child Control's Size : ScrolledComposite « SWT « Java Tutorial






Setting the Child Control's Size
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ScrolledCompositeChildSize {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    shell.setLayout(new FillLayout());

//  Create the ScrolledComposite to scroll horizontally and vertically
    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);

    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");

    child.setSize(400, 400);

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

  }
}








17.80.ScrolledComposite
17.80.1.Create the ScrolledComposite to scroll horizontally and verticallyCreate the ScrolledComposite to scroll horizontally and vertically
17.80.2.Setting the Child Control's SizeSetting the Child Control's Size
17.80.3.Setting Minimum Size for a Child ControlSetting Minimum Size for a Child Control
17.80.4.Scrollbars appear if the window is resized to be too small to show part of the buttonScrollbars appear if the window is resized to be too small to show part of the button
17.80.5.If the window is too small, scrollbars will appear.If the window is too small, scrollbars will appear.
17.80.6.Create a ScrolledComposite with wrapping content
17.80.7.Create two ScrolledComposites that scroll in tandemCreate two ScrolledComposites that scroll in tandem
17.80.8.Scroll a widget into view on focus inScroll a widget into view on focus in