質問

私が何を間違えたのでしょうか?

ここに私のコードからの抜粋があります:

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));
}

...しかし、最後のボタンがクリップされます:alt text

お兄さん82:それはうまくいきませんでした。

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

役に立ちましたか?

解決

これは使用する際の一般的なハードルです 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);
}

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

他のヒント

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

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();
}

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

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top