繁体   English   中英

如何强制StyledText在SWT中换行

[英]How to force StyledText to break line in SWT

我正试图迫使StyledText打破界限,但效果无望。 相反,它将外壳的大小扩展到最大行的宽度。

我正在尝试通过创建扩展外壳的类来实现这一目标

我的构造函数

    super(SWT.ON_TOP | SWT.NO_TRIM | SWT.NO_FOCUS | SWT.NO_SCROLL);
    FillLayout layout = new FillLayout();
    layout.marginHeight = 1;
    layout.marginWidth = 1;
    setLayout(layout);

    mForm = new ManagedForm(this);
    FormToolkit toolkit = mForm.getToolkit();
    body = mForm.getForm().getBody();

    FillLayout layout2 = new FillLayout();
    layout2.spacing = 2;
    body.setLayout(layout2);

    body = toolkit.createComposite(body, SWT.BORDER );

当我想要插入并显示文本时。 我就是这样

    String text = 
    body = mForm.getToolkit().createComposite(parent, SWT.BORDER);
    GridLayout l = new GridLayout();
    l.marginHeight = 0;
    l.marginWidth = 1;

    body.setLayout(l);  

    StyledText bodyText = createDisabledText(body, text);

    mForm.getForm().getContent().pack(); 
    mForm.getForm().reflow(true);
    pack();

   setVisible(true);

和我创建disabledText:

private StyledText createDisabledText(Composite parent, String value)
{
    StyledText t = new StyledText(parent, SWT.SHADOW_NONE);
    t.setText(value);
    t.setEditable(false);
    t.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    return t;
}

一切都在扩展外壳的类中。 我做错了还是有像set maxSize这样的方法?

在您的createDisabledText方法中,尝试将SWT.WRAP样式传递给StyledText构造函数。

StyledText t = new StyledText(parent, SWT.SHADOW_NONE | SWT.WRAP);

暂无
暂无

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

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