简体   繁体   English

如何包装swt标签文本

[英]How to wrap a swt label text

I'm trying to wrap this text automatically, but it doesn't wrap. 我正在尝试自动包装此文本,但它不会换行。 I'm trying with the code below, not sure what's wrong with the code. 我正在尝试使用下面的代码,不确定代码有什么问题。 This is 这是

protected Control createContents(Composite parent){
    Composite composite = new Composite(parent, SWT.WRAP);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(SWT.HORIZONTAL, SWT.TOP, false, false));

    Group group = new Group(composite, SWT.NONE);
    group.setText("my group");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    Button button = new Button(group2,SWT.CHECK);
    GridData data = new GridData(SWT.HORIZONTAL, SWT.TOP, false, true, 1, 1);
    button.setLayoutData(data);

    Label label= new Label(group, SWT.WRAP);
    data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(data);
    label.setText("my long text is very long, I need to wrap this very long text lalalalalalalalalalalalalala");
}

The composite's layoutdata also needs to have grabExcessHorizontal space set to true, ie: 复合的layoutdata也需要将grabExcessHorizontal空间设置为true,即:

composite.setLayoutData(new GridData(SWT.NONE, SWT.TOP, true, false));

I think the wrapping label and all of its parent composites need to have that. 我认为包装标签及其所有父组合都需要具备。

By the way, the style-bit SWT.WRAP doesn't make sense for class Composite. 顺便说一下,样式位SWT.WRAP对于类Composite没有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM