Thursday, January 18, 2007

UTF-8 in Netbeans 5.5

I have Netbeans 5.5 with JDK 6.0 running on my Windows Vista RC1 for a month now. Problem arises when I need to use Thai language in my Java Applet project.


From the figure in the left, I try to draw a string, "สวัสดีครับ", but it was displayed as "??????????". By the way, If you enter your Thai texts via Netbeans' properties editor they will be displayed properly like the caption of JButton in my applet. (If you examined the designer generated sources, you would see escaped string instead of pure Thai text)

To fix the problem, right click on your java source file, click on properties, change the encoding to "utf-8".


After changed the file encoding, you have to close your file and reopen it. You can now edit your file and it will be saved as UTF-8.



But if you compile your file at this point, you will get something like "unmappable character for encoding XXX" error. There is one more little thing to change, Go to project properties window by right click on the project name in the project navigator and click on properties, Go to build->compile and add "-encoding utf-8" at the Additional Compiler Options.


This is my result,


This solution may apply to other foreign languages too.

14 comments:

Masaki said...

Nice tip!! Can I introduce in my blog? I'd like to use the picture with Thai characters.

.:: m3rLinEz ::. said...

Sure, you can :)
Thanks for visiting.

Leong said...

I am a Chinese from Macau, SAR. We have to use Chinese (Simplified and Traditional), Portuguese and, of course, English here.

I have been looking for the solution to this utf-8 encoding problem for over a year and even asked Sun support team but received no clear instructions. They may not use eastern languages like us.

I could find the encoding option easily in Eclipse but not in Netbeans. I tried several other ways like native2ascii.exe or other editors and compiled with -encoding utf-8 in a command line box. It works but not convenient.

Anyway, thank you very much for such a good tip with considerate illustrations.

Timothy Leong, leongcheokteng@gmail.com

deans4j said...

ยินดีด้วยน้อง ได้ลง blog ของซันด้วยนะ

http://blogs.sun.com/katakai/entry/how_to_use_utf_8

http://www.planetnetbeans.org/

ตามมาดู ที่แท้ก็น้องที่เคยสอนเมื่อปีที่แล้วนี่เอง โลกกลมดีจริงๆ

.:: m3rLinEz ::. said...

ว้ากกกก

สวัสดีครับพี่ดีน :D

bact' said...

หาวิธีแก้ใน NetBeans 6.0 M6 ไม่เจอ
มันไม่มี encoding ให้เลือกเลย

แต่ถ้าเกิดอยากแก้ compile option ไปแก้ในไฟล์ build.xml ได้
หา element ที่ชื่อ javac แล้วก็เพิ่ม attribute ชื่อ encoding="utf-8"

CzechBier said...

Hello Folks,
start up netbeans with this param

"C:\Program Files\netbeans-XX\bin\netbeans.exe" -J-Dfile.encoding=UTF-8

Eduardo Bertassi said...

There's another point I would like to add...

I did all the changes that were recomended, however I wasn't able to see the characters properly.

Then, I decided to clean and rebuild my project. To my fortune, everything started do work as I expected.

Thanks for the tip!

antajan said...

Thank you so much for utf-8 in netbeans. It's helful real for me.

Anonymous said...

ผมลองเอาไปใช้กับ RMS อ่ะคับแต่มันก้อยังเป็นเหมือนเดิม
("??????")ต้องทำไงอ่ะคับ

.:: m3rLinEz ::. said...

RMS นี่ใช่ Record Management Store ของพวก J2ME รึเปล่าครับ?

พอดีผมไม่เคยมีประสบการณ์กับ J2ME และบางทีมันอาจจะไม่ใช่ปัญหาเรื่อง UTF-8 ก็ได้นะครับ ผมแนะนำให้ลองหาข้อมูลในเว็บบอร์ดแบบนาริสาดู ยังไงลองดูนะครับ

http://www.narisa.com/forums/index.php?showforum=23

hoanyeuhue said...

leave your comment

sam said...

Thanks so, its useful >:d<

Wow Thinking said...

Thank you for sharing this one, call us at Hotmail Technical Support Phone Number Canada 1-844-305-9778 for quick solution if you are facing trouble with your Hotmail account in Canada and USA.