SWT:组的高度

SWT: height of Group

我想要 grpModelProperties 的高度更低。组内文本框上下距离要一样怎么办?

public void createControl(Composite parent) {

     Composite composite = new Composite(parent, SWT.NULL);
     composite.setLayout(new FillLayout());

     Group grpModelProperties = new Group(composite, SWT.SHADOW_IN);
     grpModelProperties.setText("ETL Transformation Model");
     grpModelProperties.setLayout(new GridLayout(2, false));


     GridData data = new GridData(GridData.FILL_HORIZONTAL);
     text = new Text(grpModelProperties, SWT.NONE);
     text.setLayoutData(data);

     Button button = new Button(grpModelProperties, SWT.PUSH);
     button.setText("File System...");
     button.addSelectionListener(new SelectionAdapter() {
     public void widgetSelected(SelectionEvent e) {
     FileDialog dialog = new FileDialog(getShell(), SWT.NULL);
     String path = dialog.open();

     if (path != null) {
     File file = new File(path);
     if (file.isFile())
      displayFiles(new String[] { file.toString()});
      else
      displayFiles(file.list());

     }
}

您已为包含 GroupComposite 指定 FillLayout,因此正在拉伸该组以填充对话框区域。

为合成使用不同的布局:

Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout());

Group grpModelProperties = new Group(composite, SWT.SHADOW_IN);
grpModelProperties.setText("ETL Transformation Model");
grpModelProperties.setLayout(new GridLayout(2, false));

// Layout data for the group in the composite,
// Fill the row, stays at the top of the dialog
grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

这里我使用了 GridLayout 并将组的 GridData 设置为仅填充该行。