Java by API/org.eclipse.swt.widgets/Sash

Материал из Java эксперт
Перейти к: навигация, поиск

new Sash(Composite parent, int style)

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");
    shell.setLayout(new FillLayout());
    new Text(shell, SWT.BORDER);
    new Sash(shell, SWT.VERTICAL);
    new Text(shell, SWT.BORDER);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





new Sash(shell, SWT.VERTICAL)

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");
    
    
    shell.setLayout(new FormLayout());
    Sash sash = new Sash(shell, SWT.VERTICAL);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0); 
    data.bottom = new FormAttachment(100, 0); 
    data.left = new FormAttachment(50, 0); 
    sash.setLayoutData(data);
    // Create the first text box and attach its right edge
    // to the sash
    Text one = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    one.setLayoutData(data);
    Text two = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    two.setLayoutData(data);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





Sash: addSelectionListener(SelectionListener lis)

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MainClass {
  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");
    shell.setLayout(new FormLayout());
    final Sash sash = new Sash(shell, SWT.VERTICAL);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0); // Attach to top
    data.bottom = new FormAttachment(100, 0); // Attach to bottom
    data.left = new FormAttachment(50, 0); // Attach halfway across
    sash.setLayoutData(data);
    sash.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        ((FormData) sash.getLayoutData()).left = new FormAttachment(0, event.x);
        sash.getParent().layout();
      }
    });
    Text one = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    one.setLayoutData(data);
    // Create the second text box and attach its left edge
    // to the sash
    Text Three = new Text(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    Three.setLayoutData(data);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}