I am currently working on a private project that uses a normal java JFrame, in which I paint an image (in form of an int[][] with ARGB-values). Then I plot this image pixel by pixel inside the paint()-method. I have to do this, because I want to shift/zoom the image to my liking. When I enlarge the window to my screen size (2560*1600) one run takes about 10 secs. Doing the same whilst just moving the mouse around this time decreases to ca. 1.5 secs. Has anyone an explanation for this 7-time boost? Thanks! Bike
Asked
Active
Viewed 31 times
0
-
Maybe [relevant post?](https://stackoverflow.com/questions/57948299/why-does-my-custom-swing-component-repaint-faster-when-i-move-the-mouse-java) – Nexevis Apr 07 '22 at 19:04
-
It's long but check out this article on low latency painting in Java by Pavel Fatin: https://pavelfatin.com/low-latency-painting-in-awt-and-swing/ – markspace Apr 07 '22 at 19:29
-
1You should also consider that Swing is designed for traditional GUIs and not for animation or fast updates. The `AffineTransform` in each draw call is expensive. Update the buffer directly if you need more consistency. Or use OpenGL with a library like Jogl or LWJGL. – markspace Apr 07 '22 at 19:43
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 08 '22 at 02:55
-
Actually it is not really a problem, I just wanted to understand why. If you want my question is: "How can I make the repaint()-method work fast without moving the mouse?" - Thanks – Bike Apr 08 '22 at 16:26
-
@Nexevis That seems to be quite the same kind of behaviour. Thanks, I just wonder why I did not find this question during my research... – Bike Apr 08 '22 at 16:49
-
@markspace Thanks for your suggestion. I just don't understand which buffer you are talking about? – Bike Apr 08 '22 at 17:00
-
A buffer is any object used to send data to a screen or rendering engine. Sorry for being unclear. Here a buffer would be any object that you are making draw calls on or setting individual pixels. Doesn't matter if it's an array of bytes or some higher level object. – markspace Apr 08 '22 at 19:00