Create a Sash in SWT

In this section, you will study how to create a Sash
In SWT, the class Sash represent a selectable user interface object that
allows the user to drag the outline. We have create the Sash first, so that the
controls can be attached to it. We have used the class FormData to define
the attachments of a control in a FormLayout. To set the FormData into control,
we have used the method setLayoutData() and pass the object of this class
to the method.
Create the first text box and attach its right edge to the sash. Then create
second text box and attach its left edge to the sash.The sash is in between the
text boxes.
Here is the code of SashExample.java
import org.eclipse.swt.*;c
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Event;
public class SashExample {
public void run() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Show Sash ");
create(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void create(Composite composite) {
composite.setLayout(new FormLayout());
final Sash sash = new Sash(composite, 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);
Text text1 = new Text(composite, SWT.BORDER | SWT.WRAP);
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);
text1.setLayoutData(data);
Text text2 = new Text(composite, SWT.BORDER| SWT.WRAP);
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);
text2.setLayoutData(data);
}
public static void main(String[] args) {
new SashExample().run();
}
}
|
Output will be displayed as:

Download Source Code
