开发者

SWT Composite maximum size

I have a ScrolledComposite, the contents of which are being truncated. I have Googled and a开发者_高级运维m aware that it is a known issue on Windows.

The only suggested workaround I can find is to use the canvas.scroll functionality.

Given the age of the issue, I was wondering if there is a nicer workaround?

Thank you!

(EDIT: At the time of writing, the link was: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java?view=markup&content-type=text%2Fvnd.viewcvs-markup&revision=HEAD)


(the link you posted gave a 400 Error)

Not sure if my issue was the same, but I ran into a truncation issue with ScrolledComposite as well. The problem was that when I resized the Composite to be scrolled and the Scrollbar became visible, the controls didn't account for the space taken up by the scrollbar. To solve this, I added a kind-of recursive bit of code to my Resize listener on the scrolled composite:

After you have set the size of your content composite, check if the scrolledComposite's scrollbar (getVerticalBar() for example) has just become visible. If so, send a new Resize event to your listener. Here's a snippet from my code...

public void handleEvent(Event event)
{
    int newWidth = scrolledComposite.getSize().x;
    boolean hasScroll = false;
    ScrollBar scrollBar = scrolledComposite.getVerticalBar();
    if (scrollBar.isVisible())
    {
        hasScroll = true;
        newWidth -= scrolledComposite.getVerticalBar().getSize().x;
    }
    newWidth -= 8;
    Point size = contentComposite.computeSize(newWidth, SWT.DEFAULT);
    contentComposite.setSize(size);

    int scroll_multiplier = size.y / 50;
    scrollBar.setIncrement(scroll_multiplier);

    /**
     * If the scroll bar became visible because of the resize, then
     * we actually need to resize it again, because of the scroll
     * bar taking up some extra space.
     */
    if (scrollBar.isVisible() && !hasScroll)
    {
        scrolledComposite.notifyListeners(SWT.Resize, null);
    }
}

Hope this helps!

Edit: wow I didn't notice the date of the OP. Hope this ends up helping someone either way...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜