Create a Sash Form

In SWT, the class SashForm lays out a Row or Column arrangement (as specified by the orientation) and places a Sash between them. In the given example, two sash forms are created.

Create a Sash Form

Create a Sash Form

     

In this section you will study how to create a Sash Form.

In SWT, the class SashForm lays out a Row or Column arrangement (as specified by the orientation) and places a Sash between them. In the given example, two sash forms are created. The first form is set to Horizontal and the second one is set to Vertical. Each containing a text and a label by using the class Text and Label. The form 1 is the parent of form2.

 

 

 

 

Following code can change the size of text and panel.

text1.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) { }
public void controlResized(ControlEvent e) {
System.out.println("size changed");
}
});

The label1 calls the MouseListener class. The method getMaximizedControl() returns the control that is currently maximized in the SashForm. The method setMaximizedControl(null) specifies the control that should be take up in the form.

Following code sets the form2 null, on double clicking the label1:

form2.setMaximizedControl(null);

Here is the code of SashFormExample.java

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;

public class SashFormExample {
  Display display = new Display();
  Shell shell = new Shell(display);
  SashForm form1;
  SashForm form2;

  public SashFormExample() {
  shell.setLayout(new FillLayout());
  
  form1 = new SashForm(shell, SWT.HORIZONTAL);
  final Label label1 = new Label(form1, SWT.BORDER | SWT.CENTER);
  label1.setText("Label 1");
  Text text1 = new Text(form1, SWT.CENTER| SWT.WRAP);
  text1.setText("Text 1");
  
  form2 = new SashForm(form1, SWT.VERTICAL);
  final Label label2 = new Label(form2, SWT.BORDER |SWT.CENTER);
  label2.setText("Label 2");
  Text text2 = new Text(form2, SWT.CENTER| SWT.WRAP);
  text2.setText("Text 2");
  
  text1.addControlListener(new ControlListener() {
  public void controlMoved(ControlEvent e) {
  }
  public void controlResized(ControlEvent e) {
  System.out.println("size changed");
  }
  });
  form1.setWeights(new int[]{1, 2, 3});
  label1.addMouseListener(new MouseListener() {
  public void mouseDoubleClick(MouseEvent e) {
  if(form2.getMaximizedControl() == label1)
  form2.setMaximizedControl(null);
  else
  form2.setMaximizedControl(label1);
  }
  public void mouseDown(MouseEvent e) {
  }
  public void mouseUp(MouseEvent e) {
  }
  });
  shell.setText("Sash Form");
  shell.setSize(350, 200);
  shell.open();
  while (!shell.isDisposed()) {
  if (!display.readAndDispatch()) {
 display.sleep();
  }
  }
  display.dispose();
  }
  public static void main(String[] args) {
  new SashFormExample();
  }
}

Output will be displayed as:

Download Source Code