1

我有一个StyledText小部件(SWT)ScrolledComposite,它应该显示日志文件的内容。不幸的是,日志文件中有数千行,所以我来到了小部件在 ~ 2200 行之后切断了文本的地步。

我发现这篇文章引用了这份报告,该报告指出 Windows 中的小部件存在高度限制,我的理论是我已经达到了这个限制。

我的问题是我该如何处理这个问题。显示包含这么多行的文本的解决方法是什么?

编辑:我发现只有在使用内部 a
时才会发生这种情况。如果我使用平原没有问题。 StyledTextScrolledCompositeStyledText

这是要重现的代码:

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.Display;
import org.eclipse.swt.widgets.Shell;

public class StyledTextLimit {

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

        ScrolledComposite scrollComp = new ScrolledComposite(shell,
                SWT.H_SCROLL | SWT.V_SCROLL);

        StyledText text = new StyledText(scrollComp, SWT.NONE);
        text.setSize(100, 500);

        scrollComp.setContent(text);
        scrollComp.setExpandHorizontal(true);
        scrollComp.setExpandVertical(true);

        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < 5000; i++) {
            builder.append(i);

            builder.append(" ");

            for (int j = 'a'; j < 'a' + 200; j++) {
                builder.append((char) j);
            }

            builder.append("\n");
        }

        text.setText(builder.toString().trim());

        scrollComp.setMinSize(text.computeSize(SWT.DEFAULT, SWT.DEFAULT));


        // shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }

}
4

2 回答 2

0

我认为没有必要将其包装StyledTextScrolledComposite. StyledText必要时会自行显示滚动条。

我建议使用StyledText没有ScrolledComposite.

当然,StyledText它能够保存的文本也有限制。但是,此限制应远高于 2200 行。如果StyledText仍然溢出,那么您将不得不截断要显示的日志。

于 2016-09-12T19:54:26.300 回答
0

尽管@Rüdiger Herrmann 帮助我解决了我的问题,但我仍然觉得我应该帮助那些可能遇到与我相同的问题而没有可能摆脱ScrolledComposite.

因此,我想链接处理该问题的这篇文章。ScrolledComposite

于 2016-09-13T14:11:50.760 回答