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?
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.
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!
There are no new questions, but there may be new answers.
Joined: Mar 19, 2013
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.
subject: java Label object not displaying ascii chars (128-159)