Demonstrates ScrolledComposite : Scroll « SWT JFace Eclipse « Java






Demonstrates ScrolledComposite

Demonstrates ScrolledComposite

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates ScrolledComposite
 */
public class ScrolledCompositeTest {
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  private void createContents(Composite parent) {
    parent.setLayout(new FillLayout());

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

    // Create a child composite to hold the controls
    Composite child = new Composite(sc, SWT.NONE);
    child.setLayout(new FillLayout());

    // Create the buttons
    new Button(child, SWT.PUSH).setText("One");
    new Button(child, SWT.PUSH).setText("Two");
    /*
     * // Set the absolute size of the child child.setSize(400, 400);
     */
    // Set the child as the scrolled content of the ScrolledComposite
    sc.setContent(child);

    // Set the minimum size
    sc.setMinSize(400, 400);

    // Expand both horizontally and vertically
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
  }

  public static void main(String[] args) {
    new ScrolledCompositeTest().run();
  }
}


           
       








Related examples in the same category

1.Scroll SWT widgets into view when they get focusScroll SWT widgets into view when they get focus
2.Create two ScrolledComposites that scroll in tandemCreate two ScrolledComposites that scroll in tandem
3.Create a ScrolledComposite with wrapping contentCreate a ScrolledComposite with wrapping content
4.Scroll a control in a scrolled compositeScroll a control in a scrolled composite
5.Scroll a child control automaticallyScroll a child control automatically
6.scroll an image (flicker free, no double buffering)scroll an image (flicker free, no double buffering)