【问题标题】:How to force StyledText to break line in SWT如何强制 StyledText 在 SWT 中换行
【发布时间】:2013-08-23 21:32:13
【问题描述】:

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

我试图通过创建扩展 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;
}

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

【问题讨论】:

    标签: java eclipse shell swt eclipse-rcp


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-05-29
      • 1970-01-01
      • 2013-09-01
      • 2013-06-08
      • 2013-11-14
      • 1970-01-01
      • 2012-08-29
      • 2014-11-30
      • 2014-10-16
      相关资源
      最近更新 更多