• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Missing Characters

 
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have been looking at a Swing app that has some special characters in it. The compiler warned me when I tried to run it in Netbeans that they might not display properly. Then the characters in question were displayed as boxes. This seems like an obvious error to do with encoding so hopefully someone can tell me how to fix it. Thanks.

Antonio
 
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please start by telling us what the characters are. Some OSs have difficulty with some characters, but it shouldn't, in theory, make any difference to Swing.
 
Antonio Moretti
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They were the Swedish extra alphabetical characters: ä, ö and å.
 
Campbell Ritchie
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Antonio Moretti wrote:. . . ä, ö and å.

Is that U+00E4, U+00E5 and U+00F6, as on this Unicode page? 00E4=ä 00E5=å 00F6=ö I got those characters to show correctly from JShell:

jshell> import javax.swing.JOptionPane;

jshell> JOptionPane.showMessageDialog(null, "00e4=\u00e4, 00e5=\u00e5, \u00f6=\u00f6");

What OS are you using? What happens when you put the above code into a class and compile it at the command line/terminal? You can put that one statement into the main() method.
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing you need to find out is: What encoding is the file which contains those characters in? (I'm guessing it's source code but you didn't specify that.)

It's likely you will say "How should I know?" Well, if you are looking at the file with some kind of text editor then that text editor will be using a suitable encoding, since you are seeing them correctly. So either the text editor was told what encoding to use, or it's using a default encoding.

Next, it looks like Netbeans is using a different encoding, since it tells you upfront that it doesn't recognize them as Unicode characters and it displays them as something which the font doesn't recognize as characters. So telling Netbeans to use the correct encoding (as identified from the first step) would fix that problem.

 
Paul Clapham
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually... I just realized that when you said "the characters in question were displayed as boxes" you might have meant that Netbeans displayed them as boxes. I had sort of assumed that you meant that running the code resulted in them being displayed as boxes.

(Characters are displayed as boxes because the font used to display them doesn't have a glyph for them.)

So my suggestion now is when you see the characters appearing in Netbeans as boxes instead of ä, ö and å, you should simply correct them to whichever of ä, ö and å they are supposed to be.
 
Saloon Keeper
Posts: 24558
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you see squares where you're expecting characters, that's an indication that the font that's displaying that text doesn't have graphics (glyphs) defined for those characters.

When you're developing an app with an IDE, you often have more than one font involved and some of them may support the characters of interest and some may not.

In particular, the font that the IDE uses for its text editors may be completely unrelated to the font(s) used by the application.

That's fine, but it's hard to edit text when it doesn't render, so you might have to adjust your IDE preferences so that it edits using a more useful font.

Likewise, it's not going to win you any friends if your GUI app doesn't use fonts that are compatible with the character set you're expecting it to handle.

Note that fonts generally don't match exactly. Fonts are selected from the computer's font collection based on a "best-match" algorithm. So if a system doesn't have Helvetica installed, it may pick Arial as the nearest approximation. Just make sure that the systems of interest have compatible glyph sets.
 
reply
    Bookmark Topic Watch Topic
  • New Topic