SWT StyledTextには高さの制限がありますか?
-
12-10-2019 - |
質問
ScrolledComposite内に表示されるStyledTextボックスを含むアプリケーションを作成しようとしています。 StyledTextボックスに多数の行を表示するのに苦労しています(2,550を超えると問題を引き起こすようです)。
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テキストで発生します
解決
これは実際にはWindowsの制限です。複合材料は、Windowsでは特定のサイズのみであり、32767以下です(ピクセル、私は想定しています)。
これは、実際には32767> 32767ではないため、ScrolledCompositeの発見です。一方、MainCompの場合、実際のサイズは32767を超えており、これが私たちが遮断された場所です。
当初、私はこれが日食のバグだと思って、これがWindowsの問題/機能であると知らされた報告書を提出しました。 https://bugs.eclipse.org/bugs/show_bug.cgi?id=333111
他のヒント
おそらく、この問題を解決して、逆の方向に進み、「他のもの」をstyledtext内に配置することで、この問題を解決できますか?その結果、 ScrolledComposite
. 。 styledTextは、画像とコントロールの両方を埋め込むことをサポートしており、リスナーを実装できます(たとえば VerifyListener
)ユーザーが埋め込みオブジェクトを削除しないようにするために - それがあなたが望むものである場合。
サンプルコードは次のとおりです。
- http://www.java2s.com/tutorial/java/0280__swt/styledtextembedimages.htm
- http://www.java2s.com/tutorial/java/0280__swt/styledtextembedcontrols.htm
コントロールを2番目の例よりも良く見せたい場合は、テキスト領域の幅全体をコントロールすることができます(そして、エリアがサイズ変更されたときのイベントを聞いてください - 使用します - 使用します styledText.addListener(SWT.Resize, new Listener() ...
).