トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

Text

SWTのTextコンポーネントもButton同様、コンストラクタの引数によって単一行or複数行、ボーダーの有無、スクロールバーの有無等を指定することができます。以下のサンプルはGridLayoutを使って、コンポーネントのサイズが伸縮するようになっています。

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TextSample1 {
  public static void main(String[] args){
    Display display = new Display ();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1,true));
    shell.setText("TextSample1");
    
    // 単一行テキストボックスを作成
    Text text1 = new Text(shell,SWT.SINGLE|SWT.BORDER);
    text1.setText("単一行のテキストボックスです");
    GridData gridData1 = new GridData();
    gridData1.horizontalAlignment = GridData.FILL;
    gridData1.grabExcessHorizontalSpace = true;
    text1.setLayoutData(gridData1);
    
    // 複数行テキストボックスを作成
    Text text2 = new Text(shell,SWT.MULTI|SWT.BORDER|SWT.H_SCROLL|SWT.V_SCROLL);
    text2.setText("1行目\n2行目");
    GridData gridData2 = new GridData();
    gridData2.horizontalAlignment = GridData.FILL;
    gridData2.verticalAlignment = GridData.FILL;
    gridData2.grabExcessHorizontalSpace = true;
    gridData2.grabExcessVerticalSpace = true;
    text2.setLayoutData(gridData2);
    
    shell.setSize(200,200);
    shell.open();

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

最終更新時間:2004年03月09日 03時35分56秒