2010-09-27 163 views
5

我有一个ScrolledComposite,其内容被截断。我有谷歌搜索,并意识到这是Windows上的一个已知问题。SWT复合最大尺寸

唯一的建议的解决办法我能找到的是使用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

回答

3

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

不知道如果我的问题是一样的,但我跑进ScrolledComposite也是截断问题。问题是,当我调整要滚动的复合并且滚动条变得可见时,控件没有考虑滚动条占用的空间。为了解决这个问题,我在滚动组合上的Resize侦听器中添加了一种递归的代码位:

设置了内容组合的大小后,检查是否滚动组合框的滚动条(例如,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的日期。希望这最终能帮助别人......