SWT Composite最大尺寸

时间:2010-09-27 13:49:40

标签: size swt composite scrolledcomposite

我有一个ScrolledComposite,其内容被截断。我用谷歌搜索,并意识到这是Windows上的一个已知问题。

我能找到的唯一建议的解决方法是使用canvas.scroll functionality

考虑到问题的年龄,我想知道是否有更好的解决方法?

谢谢!

(编辑:在撰写本文时,链接是: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

1 个答案:

答案 0 :(得分:3)

(您发布的链接给出了400错误)

不确定我的问题是否相同,但我也遇到了ScrolledComposite的截断问题。问题是当我调整Composite的大小以便滚动并且滚动条变得可见时,控件没有考虑滚动条占用的空间。为了解决这个问题,我在滚动的复合材料上为我的Resize监听器添加了一种递归的代码:

设置内容合成的大小后,检查scrolledComposite的滚动条(例如getVerticalBar())是否刚刚可见。如果是这样,请将新的Resize事件发送给您的侦听器。这是我代码中的一个片段......

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

希望这有帮助!

编辑:哇我没注意到OP的日期。希望这最终能帮助某人......

相关问题