Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I repaint efficiently when using big custom component in Swing?

I have made a custom component (derived from JComponent) which represents a draggable Bezier-curve.
(looks like a hanging cable, someone might know it from Bender or Cubase)

My problem is: The curve may become really long, let's say from top left to bottom right corners of the desktop.

This makes Swing's repaint functionality inefficient: The area of the curve is perhaps few hundred pixels, but the area of the component (being mostly 'transparent') is millions of pixels big.

My subjection impression is:
The longer the curve, the more flicker I get when dragging it.

I hope I made myself clear about the problem.

Perhaps it would help when I somehow could choose by myself, which regions of the component needs repainting at all.

EDIT:
Such a mess! I'm profiling the application using Netbeans, which helps to find inefficient code normally, but this Swing framework is making hundreds of nested calls! I just can't figure out, what is slow and why.
By the way, disabling super.paint(...) or super.paintComponent(...) doesn't help.

like image 573
ivan_ivanovich_ivanoff Avatar asked May 18 '09 14:05

ivan_ivanovich_ivanoff


1 Answers

Check out Filthy Rich Clients by Chet Haase and Romain Guy. They address these very optimizations among others along the way to producing responsive and graphically impressive UI.

like image 143
Martin OConnor Avatar answered Oct 22 '22 00:10

Martin OConnor