2008-08-29 5 views
12

내가 뭘 잘못 했습니까? 여기 SWT ScrolledComposite가 자녀의 일부를 먹지 않도록하십시오

내 코드에서 발췌 한 것입니다 :

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 : 제안을 시도했지만 스크롤바가 사라졌습니다. 나는 그것에 대해 좀 더 연구 할 필요가있다.

+0

안녕하세요, 제레미, 제 제안이 효과가 없을 때만 눈치 챘습니다. 이걸 가지고 행운이 있니? – SCdF

+0

(btw, 내 답변에 댓글을 달면 내 답변에 표시되며 놓치지 않습니다.) – SCdF

답변

12

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

크기 변경을 수신 대기 중일 때 너비가 동일하게 유지되는 크기 조정 이벤트는 무시됩니다. 이는 너비가 동일하면 컨텐츠의 높이가 변경 되어도 최소 높이에 에 영향을 미치지 않기 때문입니다.

+0

감사합니다. 문제가 해결되었습니다. – Jeremy

0

레이아웃 이후에 scrollBox의 크기를 다시 계산할 필요가 없습니까?

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

온 .setMinWidth 및 .setMinHeight를 설정하십시오 레이아웃이 완료되면 ScrolledComposite에 주 합성의 크기를 전달합니다.

관련 문제