SWT - Exemple SashForm

SWT - Exemple SashForm

Qu'est-ce que SashForm?

Dans SWT, SashForm est similaire à Group, mais il a ajouté une fonctionnalité supplémentaire, il permet à l'utilisateur d'ajuster la taille du contrôle dans l'environnement d'exécution. Le SashForm fournit cette fonctionnalité en créant une ligne mobile entre le widget enfant (bouton, étiquette, texte…). Lorsque l'utilisateur fait glisser la «ligne», il agrandit une taille de widget et réduit les autres.

Le widget SashForm prend en charge deux styles.

1) SWT.SWT.HORIZONTAL
2) SWT.VERTICAL

Comment créer un widget SashForm?

Ici, je vais montrer comment créer un widget à quatre boutons et le lier à SashForm dans un style HORIZONTAL et VERTICAL.

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SWTSashForm
{
    public static void main (String [] args) {
        Display display = new Display ();
        Shell shell = new Shell(display);
        shell.setText("SWT SashForm Example");

        shell.setLayout(new FillLayout());

        // Create the SashForm with HORIZONTAL
        SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
        new Button(sashForm, SWT.PUSH).setText("Left");
        new Button(sashForm, SWT.PUSH).setText("Right");

        // Create the SashForm with VERTICAL
        SashForm sashForm2 = new SashForm(shell, SWT.VERTICAL);
        new Button(sashForm2, SWT.PUSH).setText("Up");
        new Button(sashForm2, SWT.PUSH).setText("Down");

        shell.open();

        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }

}

image

image