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.

15 comments:

Anonymous said...

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

Unknown said...

Sure, you can :)
Thanks for visiting.

Unknown 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

Anonymous said...

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

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

http://www.planetnetbeans.org/

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

Unknown said...

ว้ากกกก

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

bact' said...

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

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

Anonymous said...

Hello Folks,
start up netbeans with this param

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

Anonymous 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!

Anonymous said...

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

Anonymous said...

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

Unknown said...

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

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

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

Unknown said...

leave your comment

Unknown said...

Thanks so, its useful >:d<

Linksys router login said...

valuable blog with great content.. thanks for sharing..
Mywifiext net

AOL Technical Support said...

With so many attractive features, AOL has become one of the best email providers among its users. Despite various features, a client may face several technical problems related to AOL and he may not be able to sort out all the issues due to lack of adequate skills or disputes in the computer system. Just in case the issues are not well repaired, try to procure the aid at our toll-free helpline number. With extraordinary services of AOL Technical Support, you will be able to tackle all the issues within minutes. There is no doubt to say that our engineers can show best search practices, create custom search filters and customize search settings.