문제

내가 뭘 잘못했나요?

다음은 내 코드에서 발췌한 내용입니다.

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

bigbrother82:작동하지 않았습니다.

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

레이아웃 후에 스크롤박스의 크기를 다시 계산할 필요가 없나요?

레이아웃이 완료되면 ScrolledComposite에서 .setMinWidth 및 .setMinHeight를 설정하여 기본 합성 크기를 전달해 보세요.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top