Java JComponent调整大小滞后 [英] Java JComponent lag on resize

查看:88
本文介绍了Java JComponent调整大小滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能提供一个见解,为什么当调整框架大小时,绘制少量矩形等简单形状的JPanel会明显滞后吗?

Can anyone give insight as to why a JPanel that is drawing simple shapes such as rectangles, in small quantity, could lag noticeably when resizing the frame?

我认为,通过添加一个用于调整窗口大小的事件并将定时大小调整为1/10 s左右,可以解决此问题.但是我不太确定.

I think that by adding an event for window resize and timing the resize to 1/10 s or so, I could solve the problem. But I'm not so sure.

在查看示例代码后,我发现调整大小的滞后是由于具有一个处理程序,该处理程序通过获取屏幕的高度和宽度来缩放绘制的对象.

After reviewing the example code I found that the resize lag is due to having a handler that scales drawn objects by getting the height and width of the screen.

   this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {

                setScale( getHeight(), getWidth() );
            }
        });

有什么方法可以减轻调整大小的延迟吗?

Is there any way to smooth the resize lag?

推荐答案

此处引用的示例可扩展至成千上万节点和边缘.它可以作为有用的参考示例.一个分析器,以示例,也可能会提供一些见识.

The example cited here scales well into the thousands of nodes and edges. It may serve as a useful reference example. A profiler, for example, may also offer some insight.

这篇关于Java JComponent调整大小滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆