JAVA,AWT, Chinese box, Chinese garbled

Source: Internet
Author: User

Develop a program with a tray icon in Java,
The Chinese display of other modules is normal, for example:

Just click on the small icon in the Tray pop-up menu in Chinese is the box (Chinese box), as follows:

As a general rule of thumb, if the font is not set, use the following code to set the font:

Font f = new Font ("\u5fae\u8f6f\u96c5\u9ed1", Font.plain, 11);//Arial

Uimanager.put ("Label.font", f);

Uimanager.put ("Label.foreground", Color.Black);

Uimanager.put ("Button.font", f);

Uimanager.put ("Menu.font", f);

Uimanager.put ("Menuitem.font", f);

Uimanager.put ("List.font", f);

Uimanager.put ("Checkbox.font", f);

Uimanager.put ("Radiobutton.font", f);

Uimanager.put ("Combobox.font", f);

Uimanager.put ("Textarea.font", f);

Uimanager.put ("Editorpane.font", f);

Uimanager.put ("Scrollpane.font", f);

Uimanager.put ("Tooltip.font", f);

Uimanager.put ("Textfield.font", f);

Uimanager.put ("Tableheader.font", f);

Uimanager.put ("Table.font", f);

Finished Chinese or block, then print the font with the following code:

Graphicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment ();

String script[] = Ge.getavailablefontfamilynames ();

for (String S:script) {

System.out.print (s+ ",");

}
Found clearly written there is a song body. This depressed, tried for an afternoon, still did not fix.
Finally found the savior on the Internet (see: http://scnjl.iteye.com/blog/1282172).
The original is myeclipse operation parameter problem, really want to curse ah I ...
Here's the solution:
First:
Right-click on your class with the main function, which is the main class where your app is running, and select Run configurations in Run as:


Second, add the following line parameter code to the VM arguments under the Arguments tab and click Apply.

-dfile.encoding=gb18030



OK, and then run, it finally appeared normal Chinese:

Finally finished, Haha,
No garbled, the whole world is pure!!!!


JAVA,AWT, Chinese box, Chinese garbled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.