如何顺利滚动SWT复合?

时间:2023-01-20 21:44:46

I'm using a SWT ScrolledComposite but when I scroll in Windows I get some tearing / flickering if I scroll to fast. What can I do to double buffer or reduce this effect, or what can I do to override the default scrolling functionality and make it scroll more smoothly? There's text boxes in the scrolling area so I don't think a canvas would work.

我正在使用SWT ScrolledComposite但是当我在Windows中滚动时,如果我滚动到快速,我会得到一些撕裂/闪烁。我该怎么做才能缓冲或减少这种效果,或者我该怎么做才能覆盖默认滚动功能并使其滚动更顺畅?滚动区域中有文本框,所以我认为画布不起作用。

1 个解决方案

#1


The trick is to play with delay and use one-pixel scrolling.

诀窍是延迟播放并使用单像素滚动。

Here are parts of the code how I actually do that:

以下是我实际执行此操作的部分代码:

public void scrollOnePixelUp() {
    scrolledComposite.getContent().setLocation(0, scrolledComposite.getContent().getLocation().y - 1);
}

public void scrollOnePixelDown() {
    scrolledComposite.getContent().setLocation(0, scrolledComposite.getContent().getLocation().y + 1);
}

private int pixelScrollDelay = 50;//ms

scrollingThread = new Thread() {
    public void run() {
        doScrolling = true;
        int i = 0;
        while((i < scrollLength) && running && doScrolling) {
            i++;

            if (d.isDisposed())
                return;
            d.asyncExec(new Runnable() {
                public void run() {
                    if (scrollUp)
                        scrollOnePixelUp();
                    else
                        scrollOnePixelDown();
                }                       
            });


            try {
                sleep(pixelScrollDelay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        doScrolling = false;
    }
};

Hope that helps!

希望有所帮助!

#1


The trick is to play with delay and use one-pixel scrolling.

诀窍是延迟播放并使用单像素滚动。

Here are parts of the code how I actually do that:

以下是我实际执行此操作的部分代码:

public void scrollOnePixelUp() {
    scrolledComposite.getContent().setLocation(0, scrolledComposite.getContent().getLocation().y - 1);
}

public void scrollOnePixelDown() {
    scrolledComposite.getContent().setLocation(0, scrolledComposite.getContent().getLocation().y + 1);
}

private int pixelScrollDelay = 50;//ms

scrollingThread = new Thread() {
    public void run() {
        doScrolling = true;
        int i = 0;
        while((i < scrollLength) && running && doScrolling) {
            i++;

            if (d.isDisposed())
                return;
            d.asyncExec(new Runnable() {
                public void run() {
                    if (scrollUp)
                        scrollOnePixelUp();
                    else
                        scrollOnePixelDown();
                }                       
            });


            try {
                sleep(pixelScrollDelay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        doScrolling = false;
    }
};

Hope that helps!

希望有所帮助!