フォームセクション内にSWTテーブルを表示しようとしていますが、列のサイズ変更とスクロールに問題があります。SWTセクションテーブルとスクロール
EclipseプルージングのViewPartに配置できるサンプルコードを添付しました(3.7は私が使っているバージョンです)。コードを実行し、右側の列のサイズを変更すると、テーブルには水平スクロールバーが表示されます(これは必要なものです)。
ここでセクションを折りたたんだら(「セクションタイトル」の左側にある矢印をクリックしてください)、ビューには水平スクロールバーが表示されます(これは不要です)。セクションをもう一度展開すると、ビューのスクロールが残り、テーブルにはもうテーブルがありません。
私は、ビューよりも広いテーブルを停止する方法を探しています(ネストされたコンポジットの恐ろしい組み合わせかもしれません)。
public class ExampleView extends ViewPart {
/** Note: other fields/methods removed to condense snippet */
private FormToolkit toolkit;
private ScrolledForm scrolledForm;
public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
toolkit = new FormToolkit(parent.getDisplay());
scrolledForm = toolkit.createScrolledForm(parent);
scrolledForm.setExpandHorizontal(true);
scrolledForm.setText("Form Title");
scrolledForm.getBody().setLayout(new FillLayout());
// here's the modification for the solution
scrolledForm.getBody().setLayout(
new BoundedLayout(new FillLayout(), true));
final Section section = toolkit.createSection(scrolledForm.getBody(),
Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
| Section.EXPANDED);
section.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
scrolledForm.reflow(true);
}
});
section.setText("Section Title");
final Table table = toolkit.createTable(section, SWT.FULL_SELECTION);
TableViewer viewer = new TableViewer(table);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setItemCount(10);
TableColumn col = new TableColumn(table, SWT.NONE);
col.setText("Column A");
col.setWidth(150);
col.setResizable(true);
col.setMoveable(true);
TableColumn col2 = new TableColumn(table, SWT.NONE);
col2.setText("Column B");
col2.setWidth(150);
col2.setResizable(true);
col2.setMoveable(true);
section.setClient(table);
}
}
あるとして適用されるようにマイナーアップデートを必要とするいくつかの厄介っぽい反射ハックがあります - 私はsection.setLayout 'へのコール(新FillLayoutことをソースから見ます()); 'はセクション –