Question

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.

Was it helpful?

Solution

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:

del %WINDIR%\System32\FNTCACHE.DAT

OTHER TIPS

It looks like an errant DateFormat, instances of which are "are generally not synchronized." If it's intermittent, rather than selective, verify correct use of invokeLater(), and "create separate format instances for each thread." See also Format.

Addendum: The errant symbols might arise from the DateFormatSymbols or DecimalFormatSymbols used by concrete subclasses of Format. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top