Java Swing screen artifacts
Asked Answered
E

2

7

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

Eckhart answered 10/2, 2014 at 15:23 Comment(12)
What happens, when you resize remaining window, triggering a repaint? Also, are the artifact components clickable or responsive in any way to user interaction?Eure
Do you have any further information about the machines on which this error occurs? Particularly, the Graphics Card type (vendor, and possibly driver version) ? Or any third-party software that was running in the background when this error occured? The fact that it happens on different OSes and different JREs suggests that these machines must have something else in common that causes this error.Elisavetpol
@Eure Resizing the window triggers a repaint and the artifacts vanish. The artifacts components are not responsive to user interaction. If you click them (in the case of the screenshot), it will select the row at that location in the underlying JTable and that row will be repainted.Eckhart
@Elisavetpol No, I don't have any further information that would suggest what these machines have in common. It's tough to get this kind of fairly in-depth information out of end users. If someone who has seen this before thinks that it may be graphics-card-related, I can write a script that would collect graphics card types and driver versions.Eckhart
I see, this sort of error is a pain in the .. hard to debug. All I can say until now is that an outdated graphics card driver can literally cause arbitrarily strange rendering artifacts. Does this only happen when the application in the background is also a Java/Swing application, or does it also happen on top of other applications? You might try playing with the Java 2D flags ( docs.oracle.com/javase/7/docs/technotes/guides/2d/… or d3d), but as long as there is no way to reliably reproduce the error, one will hardly find out whether this helps...Elisavetpol
@Elisavetpol Ok, I will try to gather some info on the graphics card and drivers on the affected machines and compare that to machines that are not affected.Eckhart
@Elisavetpol Also, while we can't reproduce the issue readily, some users report that it happens at least every 5 minutes. So I can definitely adjust system properties and let the users report if the problem still exists, but it will be a trial-and-error process. Do you have any thoughts about which properties are most likely to have an effect?Eckhart
Although I have never encountered such an error, it might be worth trying -Dsun.java2d.opengl=true or -Dsun.java2d.d3d=false - sorry, until now, and given the few information, this is not much more than a guess or a gut feeling... But I'm curious: Does this also happen on top of NON-Swing applications?Elisavetpol
Thanks, I'm having some users try those config changes now. This problem does not affect windows outside of the Swing application.Eckhart
OT: See The Use of Multiple JFrames, Good/Bad Practice?Duck
@AndrewThompson Interesting perspective on so many people being against multiple JFrames. I guess that's the thinking that got us Windows 8. I have never considered multiple JFrames a bad thing. I think our application would be nearly useless if we didn't allow multiple windows. MDI is an option, but our users use 2 - 4 monitors alongside other applications. Having a gigantic MDI window that takes up 4 monitors would hide those other applications.Eckhart
@Elisavetpol Adding -Dsun.java2s.d3d corrected the issue. I imagine that we could have updated video drivers and DirectX versions, but I don't really want to go to all that trouble (especially with the number of potentially affected users that may or may not be reporting the issue). Do you think there some sort of performance benefit to enabling the Direct3D support (for a data entry application)? If you want to submit that as an answer, I will accept it so you can get your reputation points. Thanks.Eckhart
E
6

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.

Elisavetpol answered 12/2, 2014 at 14:34 Comment(0)
N
4

"-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.

Nancienancy answered 6/11, 2014 at 22:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.