-1

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?

BAR
  • 15,909
  • 27
  • 97
  • 185
  • 2
    Without sample code, no, you won't get a straight answer. However, it's possible that the repaint manager is reducing the number of repaints it is scheduling to minimum set and waiting for the window resizing events to stabilise ... Possibly – MadProgrammer Mar 12 '13 at 07:58
  • 1
    I believe this is a general problem faced when programming swing, I would think experience should prevail. – BAR Mar 12 '13 at 08:05
  • 1
    Been coding in Swing for 13 years, this has always been an issue. Since we don't have direct control over the paint process, it will come down to how the repaint manager decides when it should repaint it's surface, so I believe – MadProgrammer Mar 12 '13 at 08:47
  • 1
    don't blame Swing for something wrong with the code you are not showing ;-) – kleopatra Mar 12 '13 at 10:07

1 Answers1

3

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.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045