SWT复合控件最大尺寸

5
我有一个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个回答

3

你发的链接出现了400错误。

不确定我的问题是否相同,但我也遇到了ScrolledComposite的截断问题。问题在于当我调整要滚动的复合组件的大小并且滚动条变为可见时,控件没有考虑滚动条占用的空间。为了解决这个问题,在我的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);
    }
}

希望这能帮到您!
编辑:哇,我没有注意到原帖的日期。无论如何,希望这对某人有所帮助...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接