• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Jake Jien
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic