Why is drawing on JFrame much slower than on JPanel?

My question is: WHY the same rocking procedure - the usual picture is almost 16 times faster when drawing a JPanel compared to directly on a JFrame? Is it just double buffering? It can not be, of course?

Reference Information. I had a problem with the fact that the user picture was not updated when the JFrame was invisible (especially, only partially shaded). After searching for SO, I decided to bite the bullet and figure out how to connect the JPanel subclass to the bluddy-NetBeans-form-designer form.

For those in the same situation: in NetBeans, you need to create a new standard class (not a JPanel form) that simply extends JPanel, and manually coordinate everything there (without a GUI designer, for example, a good day, sigh). Then you add a standard JPanel to your form, set its size; then right-click and select "Customize Code" and select "custom creation" in the combo box ... where it creates a new javax.swing.JPanel, replace it with a subclass.

So ... This allowed me to "do it right" and draw the component, not directly on the form. In addition, the key-listener panel offers a much faster solution than hi-expanding the key-event-dispatcher frame.

In any case, the profiler now says EXACTLY that the same drawing code runs about 16 times faster in JPanel paintComponent () as a JFrame paint () application ... and I was wondering if anyone could explain why.

Thanks in advance. Whale.


EDIT: This question is based on MISINTERPRETED METRICS. The profiler does not include / does not report the JPanel paintComponent () method in the AWT-EventQueue stream, where since my base profile includes JFrame paint (). I should have looked more carefully before asking a stupid question. My bad.

+8
java swing
source share
2 answers

JFrame is a top-level container that extends aw.Frame, which requires its own resources for drawing, while JPanel is a swing component that is displayed by the user interface thread itself.

+1
source share

β€œSwing uses the Java2D API for drawing, and according to this Java SE 7 troubleshooting guide, Java2D uses a set of rendering pipelines, which can be roughly defined as different ways to render primitives.” More specifically, Java2D It seems like a rendering pipeline connects cross-platform Java code with native graphics libraries (OpenGL, X11, D3D, DirectDraw, GDI) that can support hardware acceleration.

In Java 1.6.0_10 (aka 6u10), a "fully hardware accelerated graphics pipeline" based on Direct3D was added to Java2D for Windows to improve rendering performance in Swing and Java2D applications (enabled by default).

By default, when Java2D is used on a Windows system, both this Direct3D pipeline and the DirectDraw / GDI pipeline are enabled by default (I assume they are used for different things).

Read on: The first call to the JFrame constructor takes a lot of time during the launch of the Swing application (due to java.awt.Window ())

0
source share

All Articles