簡體   English   中英

如何向Java swt組添加填充

[英]how to add padding to java swt groups

我正在使用java swt。 我想在組內添加填充,並且嘗試如下所示。

    excelFileGroup = factory.createGroup(container, "Destination");
    FormLayout excelFileGroupLayout = new FormLayout();
    excelFileGroupLayout.marginBottom = 50;
    excelFileGroupLayout.marginTop = 10;
    excelFileGroupLayout.marginLeft = 10;
    excelFileGroupLayout.marginRight = 10;
    excelFileGroup.setLayout(excelFileGroupLayout);

即使嘗試了這一點,我也沒有填充。 還有其他方法,或者我剛剛以不正確的方式使用了它。

我應該在LayoutData中添加填充。 如果是這樣,那又如何?

感謝您的幫助。

目前尚不清楚您到底是在問什么還是您的特定要求是什么,但是我可以使用以下方法填充組的內容:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

public class GroupPadding extends Composite
{
  public GroupPadding(Shell parent, int style)
  {
    super(parent, style);
    this.setLayout(new FillLayout());

    // Group color (white)
    Color groupColor = new Color(parent.getDisplay(), new RGB(255, 255, 255));

    // Group content color (grey)
    Color groupContentColor = new Color(parent.getDisplay(), new RGB(100, 100, 100));

    Group g = new Group(this, SWT.NONE);
    g.setText("My group");
    FillLayout fl = new FillLayout();
    fl.marginHeight = 20;
    fl.marginWidth = 20;
    g.setLayout(fl);
    g.setBackground(groupColor);

    Composite c = new Composite(g, SWT.NONE);
    c.setBackground(groupContentColor);
  }

}

結果是:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM