给Swing设置统一的字体

Need Swing applicaiton program set unification Font? Answer is Yes, if you think that default Font which set by System is not good enough or you want to really control the size of application. If your application runs on several language operation system, you may find that the font are not same between them, and sometimes you can see "... " on UI instead of normal charactors as the special size is too small to show all of them, though they are shown normally on another machine with different language.

 

So here I give a simple solution to set Java Application font:

 

package com.sss.util;

 

import java.awt.Font;

 

import javax.swing.UIManager;

 

/**

 * @create Aug 10, 2009 4:26:41 PM 

 */

public class FontManager {

private Font appFont = null;

public FontManager(Font font){

appFont = font;

setAppFont();

}

/**

* Set Application font with that specified in construction parameter.

* If there is not specified font, use default font 

*/

public void setAppFont(){

if(appFont != null){

setAppFont(appFont);

}

}

/**

* Set Application Font

* @param font

*/

public void setAppFont(Font font){

// Font   font   =   new   Font("",Font.PLAIN,14);      

        UIManager.put("Button.font",font);   

        UIManager.put("ToggleButton.font",font);   

        UIManager.put("RadioButton.font",font);   

        UIManager.put("CheckBox.font",font);   

        UIManager.put("ColorChooser.font",font);   

        UIManager.put("ToggleButton.font",font);   

        UIManager.put("ComboBox.font",font);   

        UIManager.put("ComboBoxItem.font",font);   

        UIManager.put("InternalFrame.titleFont",font);   

        UIManager.put("Label.font",font);   

        UIManager.put("List.font",font);   

        UIManager.put("MenuBar.font",font);   

        UIManager.put("Menu.font",font);   

        UIManager.put("MenuItem.font",font);   

        UIManager.put("RadioButtonMenuItem.font",font);   

        UIManager.put("CheckBoxMenuItem.font",font);   

        UIManager.put("PopupMenu.font",font);   

        UIManager.put("OptionPane.font",font);   

        UIManager.put("OptionPane.messageFont",font);   

        UIManager.put("OptionPane.buttonFont",font);   

        UIManager.put("Panel.font",font);   

        UIManager.put("ProgressBar.font",font);   

        UIManager.put("ScrollPane.font",font);   

        UIManager.put("Viewport",font);   

        UIManager.put("TabbedPane.font",font);   

        UIManager.put("TableHeader.font",font);   

        UIManager.put("TextField.font",font);   

        UIManager.put("PasswordFiled.font",font);   

        UIManager.put("TextArea.font",font);   

        UIManager.put("TextPane.font",font);   

        UIManager.put("EditorPane.font",font);   

        UIManager.put("TitledBorder.font",font);   

        UIManager.put("ToolBar.font",font);   

        UIManager.put("ToolTip.font",font);   

        UIManager.put("Tree.font",font);   

        UIManager.put("Table.font",font);

}

}

 

You can use it with below code:

 

Font font = new Font("Tomaho", Font.PLAIN, 10);

FontManager fontManager = new FontManager(font);

fontManager. setAppFont();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值