Make Java swing display Chinese more beautiful

Source: Internet
Author: User
First of all, I would like to thank cocould for replying and reminding me.

Keywords: Swing jgoodies look & feel Chinese Characters

In the previous article, we mentioned that the use of third-party L & F to make the interface of Java programs more beautiful, but the Chinese characters of jgoodies L & F are changed to boxes. In addition, swing metal displays 12 bold Chinese characters by default, which is very ugly. Is there a way to display Chinese properly and be beautiful?

After looking for some information, we found that the Tohoma font is used by default in swing, rather than family font such as dialog. To display Chinese properly, set the font to dialog. It is difficult to set the font for each component in the cocould method. The following uses the Global font settings to solve this problem.

Public static void initglobalfontsetting (font fnt ){
Fontuiresource fontres = new fontuiresource (fnt );
For (enumeration keys = uimanager. getdefaults (). Keys (); keys. hasmoreelements ();){
Object key = keys. nextelement ();
Object value = uimanager. Get (key );
If (value instanceof fontuiresource)
Uimanager. Put (Key, fontres );
}
}

...........

Try {

Uimanager. setlookandfeel (
// Uimanager. getcrossplatformlookandfeelclassname ()
// Uimanager. getsystemlookandfeelclassname ()
// New COM. Sun. java. Swing. plaf. motif. motiflookandfeel ()
// "Com. jgoodies. Looks. Windows. windowslookandfeel"
"Com. jgoodies. Looks. Plastic. plasticlookandfeel"
// "Com. jgoodies. Looks. Plastic. plastic3dlookandfeel"
// "Com. jgoodies. Looks. Plastic. plasticxplookandfeel"

);

Initglobalfontsetting (new font ("dialog", Font. Plain, 12 ));

}

This completes. Let's take a look at the effect:

Related Article

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.