首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何移除物体之间的空间?

如何移除物体之间的空间?
EN

Stack Overflow用户
提问于 2014-02-19 15:54:48
回答 1查看 270关注 0票数 0

我在一行中创建了几个对象。

我想控制物体之间的空间

我怎么能做到呢?我需要改变RowLayout吗?

代码语言:javascript
复制
public static void main(String[] args)
 {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(2, false));

Composite myComposite = new Composite(shell, SWT.NONE);
myComposite.setLayout(new GridLayout(1, false));
myComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

Composite deComposite = new Composite(myComposite, SWT.NONE);
deComposite.setLayout(new RowLayout(SWT.HORIZONTAL));

Label createDetailsde = createDetailsde(deComposite);

shell.pack();
shell.open();

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

}

代码语言:javascript
复制
private static Label createDetailsde(Composite detailsComposite)
   {
     Label linkLabel = new Label(detailsComposite, SWT.NONE);
     linkLabel.setText("test");
     return linkLabel;

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-19 16:04:20

使用RowLayout#spacing = 0移除项之间的间距。下面是一些示例代码(我使用SWT.BORDER作为Labels以使间距更加明显):

代码语言:javascript
复制
public static void main(String[] args)
{
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new GridLayout(2, false));

    Composite myComposite = new Composite(shell, SWT.NONE);
    myComposite.setLayout(new GridLayout(1, false));
    myComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.spacing = 0;

    Composite deComposite = new Composite(myComposite, SWT.NONE);
    deComposite.setLayout(rowLayout);

    createDetailsde(deComposite);
    createDetailsde(deComposite);
    createDetailsde(deComposite);
    createDetailsde(deComposite);

    shell.pack();
    shell.open();

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

}

private static Label createDetailsde(Composite detailsComposite)
{
    Label linkLabel = new Label(detailsComposite, SWT.BORDER);
    linkLabel.setText("test");
    return linkLabel;

}

有间距:

无间隔的:

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21885637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档