2016-05-25 5 views
0

数日前にSWTを発見し、プラグインインターフェイスをSwingからSWTに切り替えることにしました。必要に応じてコンポーネントを配置できますが、ウィンドウのサイズを変更すると、コンポーネントのサイズがまったく変更されません。さらに、小さな文字列(テキストエリア)に大きな文字列を入力すると、サイズを変更する方法が見つからない... 次のコードは、レイアウトとコンポーネントを定義するコードです。私の間違いは(ある)です。コンポーネントはSWTでGridLayoutでサイズ変更されません

P.S:シェルを宣言する前にDisplayオブジェクトを宣言するオンラインチュートリアルがいくつかあります。私がすると、InvalidThreadAccess Exceptionが発生します。

Shell shell = new Shell(); 
    GridLayout gridLayout = new GridLayout(2, false); 
    shell.setLayout(gridLayout); 

    tree = new Tree(shell, SWT.CHECK | SWT.BORDER); 

    Text tips = new Text(shell, SWT.READ_ONLY); 
    tips.setText("Pick the files and nodes to refactor : "); 
    oldFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 
    oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n"); 
    oldFileViewer.setSize(400, 400); 

    newFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 
    newFileViewer.setText("and here is the new file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n"); 
    newFileViewer.setSize(400, 400); 
    Button ok = new Button(shell, SWT.PUSH); 

お読みいただきありがとうございます。

+2

レイアウトを使用するときは、手動でサイズを設定しないでください。これを読んでください:[SWTのレイアウトを理解する](http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html) – Baz

+1

また、[この回答を見る] GridDataと一緒に 'GridLayout'を使う方法の例については、http://stackoverflow.com/a/12929757を参照してください。 – Baz

答えて

1

setSizesetBoundsのレイアウトを試したり混ぜたりしないでください。動作しません。私はGridLayoutコントロールをレイアウトする方法を決定するために使用するGridDataを提供する各コントロールにsetLayoutDataを求めている

GridLayout gridLayout = new GridLayout(2, false); 
shell.setLayout(gridLayout); 

tree = new Tree(shell, SWT.CHECK | SWT.BORDER); 
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); 
tree.setLayoutData(data); 

Text tips = new Text(shell, SWT.READ_ONLY); 
tips.setText("Pick the files and nodes to refactor : "); 
tips.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); 

oldFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 
oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n"); 
data = new GridData(SWT.FILL, SWT.FILL, false, false); 
data.heightHint = 400; 
oldFileViewer.setLayoutData(data); 

newFileViewer = new Text(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); 
newFileViewer.setText("and here is the new file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n"); 
data = new GridData(SWT.FILL, SWT.FILL, false, false); 
data.heightHint = 400; 
newFileViewer.setLayoutData(data); 

Button ok = new Button(shell, SWT.PUSH); 
ok.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); 

:あなたのコードは次のようになりますレイアウトを使用して

注:Eclipseプラグインを作成している場合は、new Display()を呼び出すことはありません。これは、スタンドアロンSWTプログラムの作成時にのみ使用されます。 Eclipseはすでにディスプレイを作成しています。

新しいShellを作成するのではなく、基本的なダイアログ処理の多くを行うJFace Dialogクラスを使用して見てください。

関連する問題