【问题标题】:Does SWT StyledText have a height limit?SWT StyledText 有高度限制吗?
【发布时间】:2011-05-29 11:26:01
【问题描述】:

我正在尝试创建一个包含显示在 ScrolledComposite 中的 StyledText 框的应用程序。我在 StyledText 框中显示大量行时遇到困难(超过 2,550 行似乎会导致问题)。

StyledText 框本身不能有滚动条,但必须可以通过 ScrolledComposite 滚动。由于 StyledText 下方和上方还有其他项目需要滚动到,我不想要多个滚动条。

因此,对于大量数据,我有一个非常大(如高度)的 StyledText 框,它似乎在某个高度后停止。

问题是 StyledText 应该和它的内容一样高,但事实并非如此。下面出现间隙的原因是,包含的组合正在调整 StyledText 报告的高度,但实际上这不是它的高度。

这是一段简化的示例代码来说明我的问题:

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class ExpandBox2
{
    public static void main(String[] args)
    {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Example");
        shell.setLayout(new FillLayout());

        ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.V_SCROLL);
        scrolledComposite.setLayout(new FillLayout(SWT.VERTICAL));

            Composite mainComp = new Composite(scrolledComposite, SWT.NONE);
        mainComp.setLayout(new FillLayout(SWT.VERTICAL));

        StyledText styledText = new StyledText(mainComp, SWT.NONE);
        styledText.getContent().setText(bigString());

        mainComp.setSize(mainComp.computeSize(SWT.DEFAULT, SWT.DEFAULT));

        scrolledComposite.setContent(mainComp);
        scrolledComposite.setMinSize(mainComp.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
        scrolledComposite.getVerticalBar().setIncrement(10);


        shell.setSize(400, 350);
        shell.open();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) {
                display.sleep ();
            }
        }
        display.dispose();

    }

    private static String bigString()
    {
        String big = "";

        for(int i=0;i<10000;i++)
        {
            big = big + "hello\r\n";
        }

        return big;
    }

}

更新:有趣的是,这个问题发生在 SWT 标签和 SWT 文本中

【问题讨论】:

    标签: java eclipse swt styledtext scrolledcomposite


    【解决方案1】:

    也许您可以通过反过来将“其他东西”放在 StyledText 中来解决这个问题?然后使 StyledText 滚动而不是 ScrolledComposite。 StyledText 支持嵌入图像和控件,并且您可以实现侦听器(例如 VerifyListener)以防止用户删除嵌入的对象 - 如果这是您想要的。

    这里有一些示例代码:

    如果你想让你的控件看起来比第二个例子更好,你可以让你的控件占据文本区域的整个宽度(并在调整区域大小时监听事件 - 使用styledText.addListener(SWT.Resize, new Listener() ...)。

    【讨论】:

      【解决方案2】:

      这实际上是 Windows 的限制。复合材料在窗口中可能只有一定的大小,不超过 32767(像素,我假设)。

      这是为 scrolledComposite 找到的,因为它实际上不是 > 32767,它只是看起来是。而 mainComp 的实际大小是 > 32767,这就是我们被切断的地方。

      最初我认为这是一个 Eclipse 错误并提交了一份报告,告知我这是一个 Windows 问题/功能:https://bugs.eclipse.org/bugs/show_bug.cgi?id=333111

      【讨论】:

      • 该错误已关闭,因为这是 Windows 限制而不是 Eclipse 限制。
      猜你喜欢
      • 1970-01-01
      • 2013-11-14
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多