我正在尝试显示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;
}
最佳答案
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
:Composite parentComposite = new Composite(parent, SWT.NONE);
parentComposite.setLayout(new GridLayout(3, true));
parentComposite.setLayoutData(gridData);
TableViewer tableViewer1 = new TableViewer(parentComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer1.getTable().setHeaderVisible(true);
tableViewer1.getTable().setLayout(new GridLayout(1,false));
tableViewer1.getTable().setLayoutData(new GridData(200,400));
createButtonComposite(parentComposite,SWT.NONE);
TableViewer tableViewer2= new TableViewer(parentComposite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer2.getTable().setHeaderVisible(true);
tableViewer2.getTable().setLayoutData(new GridData(200,400));
关于java - 无法在滚动组合中显示TableViewer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35662977/