2012-02-23 24 views
1

多くの行を含むテーブルを作成しました。これを実行すると、すべての行が1つの大きなウィンドウに表示されます。私はどのようにテーブルに表示される行の数を制限し、他の行を表示する垂直スクロールバーを持っている必要があります。Eclipseテーブルのスクロールバーを有効にする方法

私はテーブルのsetBoundsとsetSizeを呼び出すことを試みました。しかし、それはまだ1つの大きなウィンドウにすべての行を表示しています。

 Display display = new Display(); 
     Shell shell = new Shell(display); 
     shell.setLayout(new GridLayout(1, true)); 
     Table table = new Table(shell, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); 
     table.setBounds(0, 0, 100, 100); 
     for (int i=0; i<4; i++) { 
      TableColumn column = new TableColumn (table, SWT.NONE); 
      column.setText ("Column " + i); 
     } 
     for(int i = 0; i < table.getColumnCount(); i++) { 
      table.getColumn(i).setWidth(150); 
     } 
     for(int i = 0; i < 50; i++){ 
      TableItem item = new TableItem(table,SWT.NONE); 
      item.setText(new String[]{"Item " + i,"Item " + i,"Item " + i,"Item " + i}); 
     } 
     shell.pack(); 
     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) 
      display.sleep(); 
     } 
     display.dispose(); 

答えて

1
Table table = new Table(shell, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); 
table.setLayoutData(GridDataFactory.swtDefault().hint(100, 100).create()); 

それはテーブルの位置や大きさを設定し、テーブルを含むCompositeのレイアウトであるため、あなたはsetBounds()を使用して、テーブルの大きさを設定することはできません。 SWTレイアウトに関する有益な情報については、次のリンクをご覧ください。http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html

+0

グリッドデータメソッドを使用して行うことができます。 (new GridData(SWT.FILL、SWT.FILL、true、true)) – vjk

+0

@vjk 'new GridData()'を作成し、 'heightInt'と' widthInt'で高さと幅を指定し、それを 'Table'に添付してください。これは私の答えと同じです( 'GridDataFactory'は1行で実行できます)。 – Baldrick

+0

swtレイアウトについての有益なリンクありがとう –

関連する問題