我正在尝试创建一个包含在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文本上
发布于 2010-12-23 18:36:44
这实际上是Windows的一个限制。复合体在窗口中可能只有一定的大小,不超过32767 (我假设是像素)。
这是为scrolledComposite找到的,因为它实际上并不大于32767,只是看起来是。而对于mainComp,实际大小大于32767,这就是我们被截断的地方。
最初,我认为这是一个Eclipse bug,并提交了一份报告,其中我被告知这是一个Windows问题/功能:https://bugs.eclipse.org/bugs/show_bug.cgi?id=333111
发布于 2011-08-12 09:23:10
也许你可以通过相反的方式来解决这个问题,并将你的“其他东西”放在StyledText中?然后因此使StyledText而不是ScrolledComposite滚动。StyledText支持嵌入图像和控件,您可以实现侦听器(例如VerifyListener)来防止用户删除嵌入的对象-如果这是您想要的。
下面是一些示例代码:
如果你想让你的控件看起来比第二个例子更好,你可以让你的控件占据整个文本区域的宽度(并监听调整区域大小的事件--使用styledText.addListener(SWT.Resize, new Listener() ...)。
https://stackoverflow.com/questions/4510579
复制相似问题