Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing screen artifacts

I have a Swing application with some sort of repaint issue. When a screen (JFrame) is closed, artifacts from that screen are sometimes painted over other screens. It is completely unreproducible on the 100+ developer machines at our office and most of the thousands of users using this software. For the past several years, there have been scattered reports of the issue, but we have always blamed in on the graphics card or driver. The number of reports of the issue have risen sharply, though, in the last several months, so we need to figure out the real cause.

Almost all of our clients run on Windows, and it affects both Windows 7 and 8 machines. We typically run on JRE 1.6.0_29, but the issue also happens on 1.6.0_45 and 1.7.0_51.

The picture below illustrates the issue. I outlined the artifact in red - this is part of another JFrame that was closed. When the JFrame was visible, it wasn't at that location on the screen. Also note that the columns of the JTable just above the artifacts are out of line. Lastly, notice that the artifact isn't painted just over the JTable, but over its parent JScrollPane and a separate JPanel at the very bottom of the screen.

Anybody have any ideas what could cause this?

enter image description here

like image 552
Jason Avatar asked Feb 10 '14 15:02

Jason


2 Answers

In order to have this issue "closed" (i.e. answered) here, the result from the comments:

Marco13 : Although I have never encountered such an error, it might be worth trying -Dsun.java2d.opengl=true or -Dsun.java2d.d3d=false

(referring to the VM flags listed at http://docs.oracle.com/javase/7/docs/technotes/guides/2d/flags.html#d3d )

Jason : Adding -Dsun.java2s.d3d corrected the issue.

(I assume that this referred to setting -Dsun.java2s.d3d=false, since it is enabled by default)


Regarding the question from the last comment:

"Do you think there some sort of performance benefit to enabling the Direct3D support (for a data entry application)?"

I have not yet used the d3d flag, but only the opengl flag, for some experiments, and not for performance tests. So I don't know in how far this flag noticably affects the performance. Again, my gut feeling is that for simple applications, this should not really have a noticable effect. With "simple", I mean applications that only use standard GUI components, and do not perform complex custom rendering operations via a Graphics2D in in an overridden paintComponent method. But according to the screenshot, this application might at least involve the most complex "standard GUI component" that exists in Swing - namely a JTable. So if you have, for example, a large JTable in a ScrollPane, possibly with complex custom CellRenderers, you should consider a dedicated test of the performance impact on some (preferably the slowest) of the target machines, if possible.

like image 129
Marco13 Avatar answered Oct 31 '22 08:10

Marco13


"-Dsun.java2d.opengl=true" did the trick for me when I suffered a similar problem with jTables.

However "-Dsun.java2d.d3d=false" rendered me no satisfaction.

like image 22
patrick Avatar answered Oct 31 '22 09:10

patrick