Some users of our Swing app report unusual artifacts that appear on the display. This varies from components that do not properly redraw to the second or two parts, to the point that all parts of the application will be repainted like tiled wallpapers over areas of the window.
The application was developed by developers of all levels between experienced Java guys and young guys from the university for five years or so, and, as expected, some of the AWT code is a complete mess, Now I was faced with the task of trying to fix the same bad. as much as I can, over the next few months or so.
This is easy to handle. Only deal with components in the event dispatch stream, IO asynchronously, something like that, and I hope that the message will be sent to the rest of the command.
What I would like to know is the best way to work with Graphics contexts, especially in the context of paintComponent (). I see a lot ...
public void paintComponent( Graphics g ) { super.paintComponent( g ); Graphics2D gfx = (Graphics2D)g;
Is it better to do this?
public void paintComponent( Graphics g ) { super.paintComponent( g ); Graphics2D gfx = (Graphics2D)g.create();
If the g parameter will be reused in other colors, then I do not need to restore it to a good state, cancel AffineTransforms, etc.
source share