如何为Group
设置高度和滚动?以下代码中的drawWitness
返回一个形状。它不完全在具有以下代码的组中。我该怎么办?
composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
Group grpModelProperties = new Group(composite, SWT.SHADOW_IN);
grpModelProperties.setLayout(new GridLayout(2, false));
grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Label l1 = new Label(grpModelProperties, SWT.NULL);
new Label(grpModelProperties, SWT.NONE);
Label l2 = new Label(grpModelProperties, SWT.NULL);
new Label(grpModelProperties, SWT.NONE);
Label l3 = new Label(grpModelProperties, SWT.NULL);
l1.setLayoutData(data);
l1.setText("Some Text1");
l2.setLayoutData(data);
l2.setText("Some Text2");
l2.setSize( 470, 400 );
Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL );
line.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
scrolledComposite = new ScrolledComposite( composite, SWT.H_SCROLL | SWT.V_SCROLL );
grpModelProperties1 = new Group(scrolledComposite, SWT.SHADOW_IN);
grpModelProperties1.setLayout(new GridLayout(1, false));
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 150;
grpModelProperties1.setLayoutData(data1);
grpModelProperties1.setText("Test Model");
drawWitness(model);
scrolledComposite.addListener( SWT.Resize, event -> {
int width = scrolledComposite.getClientArea().width;
scrolledComposite.setMinSize( composite.computeSize( width, SWT.DEFAULT ) );
} );
答案 0 :(得分:1)
设置组布局数据的宽度和高度提示:
GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
data.widthHint = 200;
data.heightHint = 200;
grpModelProperties1.setLayoutData(data);
要使用ScrolledComposite
,您需要以下内容:
ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
// You must set a layout on scrolled composite
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
// Additional inner composite is required
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
innerComposite.setLayout(new GridLayout());
Group grpModelProperties1 = new Group(innerComposite, SWT.SHADOW_IN);
grpModelProperties1.setLayout(new GridLayout());
grpModelProperties1.setText("Test Model");
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 400;
data1.widthHint = 400;
grpModelProperties1.setLayoutData(data1);
scrolledComposite.setContent(innerComposite);
// No need to use a resize listener
scrolledComposite.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));