SWT Shell - 内部填充/边框

时间:2014-05-06 21:46:13

标签: java swt

我有一个SWT Shell,它有一些我无法摆脱的未知填充或边框。以下是我正在谈论的内容的截图。边界问题是绿色。我如何摆脱它,因为我的元素看起来会更好地直接压在shell的一侧?

提前致谢:D

screenshot of border

public static void main(String[] args) {
    Display display = new Display();
    Shell rootShell = new Shell(display);
    rootShell.setBackground(SWTGraphicUtil.getColorSafely(0, 255, 0));

    GridLayout rootLayout = new GridLayout();
    rootLayout.numColumns = 3;
    rootLayout.horizontalSpacing = 0;
    rootLayout.verticalSpacing = 0;
    rootLayout.marginTop = rootLayout.marginRight = rootLayout.marginBottom = rootLayout.marginLeft = 0;
    rootShell.setLayout(rootLayout);

    Label lbl = new Label(rootShell, SWT.NONE);
    lbl.setText("WHAT WHAT WHAT WHAT WHAT WHAT WHAT");
    lbl.setBackground(SWTGraphicUtil.getColorSafely(255, 0, 0));

    Label lbl2 = new Label(rootShell, SWT.NONE);
    lbl2.setText("WHAT WHAT WHAT WHAT WHAT WHAT WHAT");
    lbl2.setBackground(SWTGraphicUtil.getColorSafely(255, 0, 255));

    Label lbl3 = new Label(rootShell, SWT.NONE);
    lbl3.setText("WHAT WHAT WHAT WHAT WHAT WHAT WHAT");
    lbl3.setBackground(SWTGraphicUtil.getColorSafely(0, 0, 255));

    rootShell.pack();

    rootShell.open();
    while (!rootShell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

1 个答案:

答案 0 :(得分:1)

只需为rootLayout设置另外两个变量:

rootLayout.marginWidth = 0;
rootLayout.marginHeight = 0;

这应该删除“填充”(实际上是一个边距;))。