Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java2D artifact?

I'm using Java2D for a game I'm writing and haven't had any issues using it until I started integrating it with other swing components. My problem is when the first component I add to the JFrame is not the canvas I'm drawing to, I get a weird artifact that shows up when I mouse over the scroll bar for the textpane. It happens every time I execute the application. When I have the canvas first, there's no problem.

For some reason this appears to only occur on Windows when the default Java2D pipeline is in use (which happens to be sun.java2d.d3d=true), and the artifact occurs. When I set sun.java2d.opengl=true or sun.java2d.noddraw=false AND sun.java2d.d3d=false, then it does not occur.

I'm guessing this is some kind of bug with the Direct3D Java2D pipeline? I can easily work around it, but curious to know if anyone else has run into such an issue? I'm running the latest JDK7u7, but it happens with previous versions as well. I should note that if I minimize the window and restore it, the artifact goes away and never returns until I restart the application.

with artifact: bad

with no artifact (after adding the canvas first instead of the JLabel image): good

If someone has any further info on this I'd appreciate it. Thanks!

like image 249
Consty Avatar asked Jul 14 '26 17:07

Consty


1 Answers

This is a well-know artifact from failing to honor the opacity property. Because "Swing programs should override paintComponent() instead of overriding paint()," be sure to invoke super.paintComponent() first in your implementation. There are related examples here and here.

Addendum: See also Mixing Heavyweight and Lightweight Components.

like image 103
trashgod Avatar answered Jul 16 '26 07:07

trashgod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!