I'm seeing a strange issue involving a JLabel
that is used to display a range of numbers. The text of the label is typically something like 0.0 - 100.0 (for example). The problem is that for a select few users, the text appears garbled. In this example, the text would show up as /-/,0//-/.
Here's what I know so far:
- It appears to be some sort of off-by-one bug since each character displayed is one Unicode character behind the expected character.
- The dash character between the two numbers is hard-coded in the application as a string literal.
- It's happening on various versions of Oracle JVMs including 1.6.x and 1.7.x.
- It's happening on a few select Windows 7 machines.
What could cause this type of problem? What else should I investigate? Thanks.
This happens when you're setting the font of your
JLabel
to a font corrupted in the Windows font cache.To rebuild the cache: as administrator, delete this file and reboot the PC:
It looks like an errant
DateFormat
, instances of which are "are generally not synchronized." If it's intermittent, rather than selective, verify correct use ofinvokeLater()
, and "create separate format instances for each thread." See alsoFormat
.Addendum: The errant symbols might arise from the
DateFormatSymbols
orDecimalFormatSymbols
used by concrete subclasses ofFormat
. You can verify correct use of the event dispatch thread in several ways:Examine the result of
SwingUtilities.isEventDispatchThread()
.Employ one of the schemes shown in the articles cited here.
Inspect the source code following the principles summarized in Memory Consistency Properties.
As you cannot reproduce the problem, you will have to enlist the help of your users. Ideally, you will want to solicit the following:
Host name, platform, locale & JVM version from
System.getProperty()
?Intermittent or consistent?
Screenshots?
You can make it easier for the user by filling in some details in a message prepared using
Desktop#mail()
, as suggested here.