JLabel text is garbled

送分小仙女□ 提交于 2019-12-10 10:39:25

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/16115028/jlabel-text-is-garbled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!