SWT - SashFormの例

SWT – SashFormの例

SashFormとは何ですか?

SWTでは、SashFormはGroupと似ていますが、もう1つの便利な機能が追加されました。これにより、ユーザーはランタイム環境でコントロールサイズを調整できます。 SashFormは、子ウィジェット(ボタン、ラベル、テキスト…)間に移動可能な線を作成することにより、この機能を提供します。 ユーザーが「ライン」をドラッグすると、1つのウィジェットサイズが拡大され、他のウィジェットサイズが縮小されます。

SashFormウィジェットは2つのスタイルをサポートします。

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

SashFormウィジェットを作成する方法は?

ここでは、4つのボタンウィジェットを作成し、それを水平および垂直スタイルでSashFormにリンクする方法を示します。

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