问题
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