13

私は何を間違えましたか?

これが私のコードからの抜粋です:

public void createPartControl(Composite parent) {
  parent.setLayout(new FillLayout());
  ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL);
  scrollBox.setExpandHorizontal(true);
  mParent = new Composite(scrollBox, SWT.NONE);
  scrollBox.setContent(mParent);
  FormLayout layout = new FormLayout();
  mParent.setLayout(layout);
  // Adds a bunch of controls here
  mParent.layout();
  mParent.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
}

...しかし、最後のボタンをクリップします: 代替テキスト

bigbrother82: うまくいきませんでした。

SCdF: あなたの提案を試してみたところ、スクロールバーがなくなりました。私はそれにもう少し取り組む必要があります。

4

4 に答える 4

13

これは、 を使用する際の一般的なハードルScrolledCompositeです。スクロール バーを表示する必要があるほど小さくなった場合、クライアント コントロールを水平方向に縮小して、スクロール バー用のスペースを確保する必要があります。これには、一部のラベルが行を折り返すという副作用があり、次のコントロールがさらに下に移動し、コンテンツ コンポジットに必要な最小の高さが増加しました。

コンテンツ コンポジット ( ) の幅の変更をリッスンしmParent、新しいコンテンツの幅を指定して最小の高さを再度計算setMinHeight()し、スクロールされたコンポジットを新しい高さで呼び出す必要があります。

public void createPartControl(Composite parent) {
  parent.setLayout(new FillLayout());
  ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL);
  scrollBox.setExpandHorizontal(true);
  scrollBox.setExpandVertical(true);

  // Using 0 here ensures the horizontal scroll bar will never appear.  If
  // you want the horizontal bar to appear at some threshold (say 100
  // pixels) then send that value instead.
  scrollBox.setMinWidth(0);

  mParent = new Composite(scrollBox, SWT.NONE);

  FormLayout layout = new FormLayout();
  mParent.setLayout(layout);

  // Adds a bunch of controls here

  mParent.addListener(SWT.Resize, new Listener() {
    int width = -1;
    public void handleEvent(Event e) {
      int newWidth = mParent.getSize().x;
      if (newWidth != width) {
        scrollBox.setMinHeight(mParent.computeSize(newWidth, SWT.DEFAULT).y);
        width = newWidth;
      }
    }
  }

  // Wait until here to set content pane.  This way the resize listener will
  // fire when the scrolled composite first resizes mParent, which in turn
  // computes the minimum height and calls setMinHeight()
  scrollBox.setContent(mParent);
}

サイズの変更をリッスンする際に、幅が同じままであるサイズ変更イベントを無視することに注意してください。これは、幅が同じである限り、コンテンツの高さを変更してもコンテンツの最小高さに影響しないためです。

于 2008-10-01T20:03:37.207 に答える
2

私が間違っていなければ、交換する必要があります

mParent.layout();

mParent.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));

あなたが持っているように:

public void createPartControl(Composite parent) {
  parent.setLayout(new FillLayout());
  ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL);
  scrollBox.setExpandHorizontal(true);
  mParent = new Composite(scrollBox, SWT.NONE);
  scrollBox.setContent(mParent);
  FormLayout layout = new FormLayout();
  mParent.setLayout(layout);
  // Adds a bunch of controls here
  mParent.setSize(mParent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
  mParent.layout();
}
于 2008-08-30T20:00:53.197 に答える
0

レイアウト後に scrollBox のサイズを再計算する必要はありませんか?

于 2008-08-30T00:16:36.693 に答える
0

レイアウトが完了したら、ScrolledComposite に .setMinWidth と .setMinHeight を設定して、メイン コンポジットのサイズを渡します。

于 2008-09-30T09:10:12.293 に答える