The demo code is as follows:
Copy Code code as follows:
Package swt_jface.demo9;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.widgets.Display;
Import org.eclipse.swt.widgets.Event;
Import Org.eclipse.swt.widgets.Listener;
Import Org.eclipse.swt.widgets.Sash;
Import Org.eclipse.swt.widgets.Shell;
public class Sashexample {
public static void Main (string[] args) {
Display display = new display ();
Shell shell = new shell (display);
Final Sash Sash = new Sash (Shell, SWT. BORDER | Swt. VERTICAL);
Sash.setbounds (10, 10, 15, 60);
Sash.addlistener (SWT. Selection, New Listener () {
public void Handleevent (Event e) {
System.out.println ("Selected.");
Sash.setbounds (e.x, E.y, E.width, e.height);
}
});
Shell.open ();
Sash.setfocus ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ())
Display.sleep ();
}
Display.dispose ();
}
}
Package swt_jface.demo9;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.widgets.Display;
Import org.eclipse.swt.widgets.Event;
Import Org.eclipse.swt.widgets.Listener;
Import Org.eclipse.swt.widgets.Sash;
Import Org.eclipse.swt.widgets.Shell;
public class Sashexample {
public static void Main (string[] args) {
Display display = new display ();
Shell shell = new shell (display);
Final Sash Sash = new Sash (Shell, SWT. BORDER | Swt. VERTICAL);
Sash.setbounds (10, 10, 15, 60);
Sash.addlistener (SWT. Selection, New Listener () {
public void Handleevent (Event e) {
System.out.println ("Selected.");
Sash.setbounds (e.x, E.y, E.width, e.height);
}
});
Shell.open ();
Sash.setfocus ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ())
Display.sleep ();
}
Display.dispose ();
}
}
One more example:
Copy Code code as follows:
Package swt_jface.demo9;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.custom.SashForm;
Import org.eclipse.swt.events.ControlEvent;
Import Org.eclipse.swt.events.ControlListener;
Import org.eclipse.swt.events.MouseEvent;
Import Org.eclipse.swt.events.MouseListener;
Import Org.eclipse.swt.layout.FillLayout;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.swt.widgets.Shell;
Import Org.eclipse.swt.widgets.Text;
public class Sashformexample {
Display display = new display ();
Shell shell = new shell (display);
Sashform Sashform;
Sashform SashForm2;
Public Sashformexample () {
Shell.setlayout (New Filllayout ());
Sashform = new Sashform (Shell, SWT. horizontal);
Text Text1 = new text (Sashform, SWT. CENTER);
Text1.settext ("Text in Pane #1");
Text Text2 = new text (Sashform, SWT. CENTER);
Text2.settext ("Text in Pane #2");
SashForm2 = new Sashform (Sashform, SWT. VERTICAL);
Final label Labela = new label (SashForm2, SWT. BORDER | Swt. CENTER);
Labela.settext ("Label in Pane A");
Final label Labelb = new label (SashForm2, SWT. BORDER | Swt. CENTER);
Labelb.settext ("Label in Pane B");
Text1.addcontrollistener (New Controllistener () {
public void controlmoved (ControlEvent e) {
}
public void controlresized (ControlEvent e) {
System.out.println ("resized");
Arrayutil.printarray (Sashform.getweights (), System.out);
}
});
Sashform.setweights (New Int[]{1, 2, 3});
Labela.addmouselistener (New MouseListener () {
public void MouseDoubleClick (MouseEvent e) {
if (sashform2.getmaximizedcontrol () = = Labela)
Sashform2.setmaximizedcontrol (NULL);
Else
Sashform2.setmaximizedcontrol (Labela);
}
public void MouseDown (MouseEvent e) {
}
public void MouseUp (MouseEvent e) {
}
});
Shell.setsize (450, 200);
Shell.open ();
while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Sashformexample ();
}
}