简体   繁体   English

Java JComponent调整大小滞后

[英]Java JComponent lag on resize

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? 谁能给出洞察力,为什么在调整框架大小时,绘制少量矩形等简单形状的JPanel会明显滞后?

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. 我认为,通过添加一个事件来调整窗口大小并将定时大小调整为1/10秒左右,我可以解决问题。 But I'm not so sure. 但是我不太确定。

EDIT: 编辑:

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. 例如探查器也可以提供一些见解。

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM