我有一个StyledText
小部件(SWT)ScrolledComposite
,它应该显示日志文件的内容。不幸的是,日志文件中有数千行,所以我来到了小部件在 ~ 2200 行之后切断了文本的地步。
我发现这篇文章引用了这份报告,该报告指出 Windows 中的小部件存在高度限制,我的理论是我已经达到了这个限制。
我的问题是我该如何处理这个问题。显示包含这么多行的文本的解决方法是什么?
编辑:我发现只有在使用内部 a
时才会发生这种情况。如果我使用平原没有问题。 StyledText
ScrolledComposite
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.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();
}
}