SWT 复合材料最大尺寸

发布于 2024-09-25 05:57:42 字数 784 浏览 0 评论 0原文

我有一个 ScrolledComposite,其内容被截断。我用 Google 搜索了一下,发现这是 Windows 上的一个已知问题。

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

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

谢谢你!

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

I have a ScrolledComposite, the contents of which are being truncated. I have Googled and am 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-10-02 05:57:42

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

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

设置内容复合材料的大小后,检查滚动复合材料的滚动条(例如 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的日期。希望这最终能以任何方式帮助某人......

(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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文