The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

texture (13) [Avatar] Offline
#1
I don't know why I can not display Chinese Characters with Label (the suggested demo code), but after changing it to JLabel the problem was solved. Below is my code:

...

// changed to JLabel
JLabel label = new JLabel(buffer.toString());

label.setSize(width, 75); // not changed

// changed the set method's name
// and it's corresponding value
label.setHorizontalAlignment(SwingConstants.CENTER);
...
mike.mccandless (221) [Avatar] Offline
#2
Re: Problem and solution sharing to Listing 4.14 ChineseDemo
Curious -- Label ought to work fine as well. Which java/os are you on?

I'll add a comment in the code noting that you could try javax.swing.JLabel, instead.
texture (13) [Avatar] Offline
#3
Re: Problem and solution sharing to Listing 4.14 ChineseDemo
Windows XP, JavaSE 6, Eclipse Build id: 20090621-0832

I've tried putting a println (to print the buffer.toString()) before the Lable to see if it prints anything, and it did manage to print the chinese characters stored.

So, I was pretty sure that the root of the problem was the Lable. I've no dought that Label should also work because you wrote the book with the screenshots, but what I don't understand is why it did work for me but JLabel does! Strange, isn't it?
mike.mccandless (221) [Avatar] Offline
#4
Re: Problem and solution sharing to Listing 4.14 ChineseDemo
Yes, bizarre and spooky. Write once, test everywhere!!