Java JComponent lag on resize

空扰寡人 提交于 2019-12-13 23:36:40

问题


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?

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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/15355916/java-jcomponent-lag-on-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!