permaculture playing cards*
The moose likes Beginning Java and the fly likes java Label object not displaying ascii chars (128-159) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Label object not displaying ascii chars (128-159)" Watch "java Label object not displaying ascii chars (128-159)" New topic
Author

java Label object not displaying ascii chars (128-159)

Jake Jien
Greenhorn

Joined: Mar 19, 2013
Posts: 3
I am having a problem getting ASCII characters between 128 and 159 to show up in a Label object which is inside a Panel which is in turn inside a Frame. There is other code that uses a Graphics object and drawString and Paint methods to display the same text, and that works. However, simply passing the text containing the above mentioned ascii characters like so:

lb = new Label("€‚ƒ„…†‡");

results in mostly empty boxes being displayed (there is other code that eventually displays the label in the Frame). The Euro sign comes through, as does the integral sign. Some others come through, and they are mostly modifed letters of some sort. These are Windows-1252 characters that I want to show up. Is there any way of using Label objects and getting these characters to display correctly?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to the Ranch.
Jake Jien wrote:I am having a problem getting ASCII characters between 128 and 159 ...

As you already said yourself, those are characters encoded in the Windows-1252 character set, not ASCII. ASCII is a 7-bit character encoding; only 0 to 127 are valid ASCII character codes.

If you are using these characters literally in your source file, then what is the character encoding of your source file? Is it Windows-1252? You might need to specify that explicitly to the compiler, otherwise it might interpret the source code as if it's in a different encoding, which could lead to other characters or empty boxes being displayed. The JDK compiler (javac) has an -encoding option which you can use to specify the character encoding of your source file.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Also ...
Jake Jien wrote:... a Label object which is inside a Panel which is in turn inside a Frame.

Why, in this day and age, are you using AWT components? AWT was superseded by Swing more than 10 years ago!


luck, db
There are no new questions, but there may be new answers.
Jake Jien
Greenhorn

Joined: Mar 19, 2013
Posts: 3
Thanks for following up on my question.

I use notepad++ to edit the source. To try out what you mentioned, I just typed up a simple test class to display a Label within a Frame. Made sure notepad++ was using Cp1252, compiled it with "-encoding Cp1252", ran it and the window comes up unable to display the Cp1252 characters in the Label. Only in the test mock-ups am I using the characters literally in the code.

I am basically trying to figure out the difference that allows these charcters to be displayed sometimes and other times not, within the same application, and the same 'window'. Even within this one window that is failing to display the Cp1252 characters in a Label object, where the string is passed in... a similar string, containing similar Cp1252-specific characters is able to display them when passed to the Frame's constructor as a title. Could there be a method callable on the Label object that would force the display of these characters?


Regarding the use of AWT components, I am attempting to maintain an application that was developed, well, more than 10 years ago.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java Label object not displaying ascii chars (128-159)
 
Similar Threads
File with euro char
Parsing huge file without reading into memory
ISO 8859-1 and nothing else...
getting ascii char from int only seems to work if int is less than 127
any hints for creating &/or using existing UNICODE convertor/processor?