Example usage for org.eclipse.swt.custom ScrolledComposite setShowFocusedControl

List of usage examples for org.eclipse.swt.custom ScrolledComposite setShowFocusedControl

Introduction

In this page you can find the example usage for org.eclipse.swt.custom ScrolledComposite setShowFocusedControl.

Prototype

public void setShowFocusedControl(boolean show) 

Source Link

Document

Configure the receiver to automatically scroll to a focused child control to make it visible.

Usage

From source file:org.eclipse.swt.snippets.Snippet188.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 188");
    shell.setLayout(new GridLayout());
    final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    Composite c = new Composite(sc, SWT.NONE);
    c.setLayout(new GridLayout(10, true));
    for (int i = 0; i < 300; i++) {
        Button b = new Button(c, SWT.PUSH);
        b.setText("Button " + i);
    }/* ww w .ja v  a 2 s  .  co  m*/
    sc.setContent(c);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setShowFocusedControl(true);

    shell.setSize(300, 500);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}