我试图在它们之间显示2个表格查看器和按钮。当试图
实现TableViewer
以显示水平和垂直滚动条,我无法看到TableViewer
,只能看到ScrolledComposite
。我甚至尝试在ScrolledComposite
内创建复合材料,并使用该复合材料展示TableViewer
,但仍看不到TableViewer
。有人能指出我正确的方向。
@Override
protected Control createDialogArea(Composite parent) {
GridData gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
gridData.heightHint = 500;
gridData.widthHint = 700;
Composite parentComposite = new Composite(parent, SWT.NONE);
parentComposite.setLayout(new GridLayout(3, true));
parentComposite.setLayoutData(gridData);
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(parentComposite, SWT.H_SCROLL|SWT.V_SCROLL);
scrolledComposite_1.setLayout(new GridLayout(1,false));
gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
gridData.heightHint = 200;
gridData.widthHint = 400;
scrolledComposite_1.setLayoutData(gridData);
scrolledComposite_1.setAlwaysShowScrollBars(true);
TableViewer tableViewer1 = new TableViewer(scrolledComposite_1, SWT.BORDER | SWT.SINGLE);
tableViewer1.getTable().setHeaderVisible(true);
tableViewer1.getTable().setLayout(new GridLayout(1,false));
tableViewer1.getTable().setLayoutData(new GridData(200,400));
createButtonComposite(parentComposite,SWT.NONE);
ScrolledComposite scrolledComposite_2 = new ScrolledComposite(parentComposite, SWT.H_SCROLL|SWT.V_SCROLL);
scrolledComposite_2.setLayout(new GridLayout(1,false));
gridData = new GridData(SWT.NONE, SWT.FILL, true, true);
gridData.heightHint = 200;
gridData.widthHint = 400;
scrolledComposite_2.setLayoutData(gridData);
scrolledComposite_2.setAlwaysShowScrollBars(true);
TableViewer tableViewer2= new TableViewer(scrolledComposite_2, SWT.BORDER | SWT.SINGLE);
tableViewer2.getTable().setHeaderVisible(true);
tableViewer2.getTable().setLayoutData(new GridData(200,400));
getShell().setText("My Dialog");
return parent;
}
答案 0 :(得分:1)
DataTemplate
要求您致电ScrolledComposite
告诉儿童控制,并且还需要其他不同的设置。这有效:
setContents
(和第二次相同)
但是scrolledComposite_1.setContent(tableViewer1.getTable());
scrolledComposite_1.setExpandVertical(true);
scrolledComposite_1.setExpandHorizontal(true);
scrolledComposite_1.setMinSize(tableViewer1.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT));
可以自动显示滚动条,因此您根本不需要TableViewer
:
ScrolledComposite