Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SWT-设置高度并在组中滚动_Java_Swt - Fatal编程技术网

Java SWT-设置高度并在组中滚动

Java SWT-设置高度并在组中滚动,java,swt,Java,Swt,如何设置组的高度和滚动drawWitness在下面的代码中,返回一个形状。它不完全在具有以下代码的组中。我该怎么办 composite = (Composite) super.createDialogArea(parent); composite.setLayout(new GridLayout()); GridData data = new GridData(GridData.FILL_HORIZONTAL); Group grpModelProperties = new Group(comp

如何设置
组的高度和滚动<代码>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 ) );
 } );

设置组布局数据的宽度和高度提示:

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));

好吧,这对我来说很有用,使用你展示的代码。给我们看一些更像一个窗口的东西,这样我们就可以确切地看到你在做什么。这是因为我设置了窗口的大小。当我将高度更改为100时,我看到它起作用了。如何设置scroll?您必须使用ScrollingTanks的
ScrolledComposite
。我试图使用ScrolledComposite,但我不能。我编辑了我的问题并添加了代码。非常感谢。我还有
drawWitness(model)
,它的返回类型是void,但绘制了一个形状。如何将其插入
grpModelProperties1
?我添加了
drawWitness
函数的内容。