简体   繁体   中英

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?

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?

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.

图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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