如何强制StyledText在SWT中断行

时间:2013-08-23 21:32:14

标签: java eclipse shell swt eclipse-rcp

我试图迫使StyledText破坏线,但效果无望。相反,它将我的shell的大小扩展到最大行的宽度。

我试图通过创建扩展shell

的类来实现这一目标

我的构造函数

    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;
}

所有都是在扩展shell的类中。 我做错了什么或者有像set maxSize这样的方法吗?

1 个答案:

答案 0 :(得分:0)

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

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