import java.awt.Font; |
import java.util.Enumeration; |
import javax.swing.UIManager; |
import javax.swing.plaf.FontUIResource; |
/** |
* 统一设置字体,父界面设置之后,所有由父界面进入的子界面都不需要再次设置字体 |
*/ |
public class SetPersonalFont { |
public void InitGlobalFont(Font font) { |
FontUIResource globalFont = new FontUIResource(font); |
for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys |
.hasMoreElements();) { |
Object key = keys.nextElement(); |
Object value = UIManager.get(key); |
if (value instanceof FontUIResource) { |
UIManager.put(key, globalFont); |
} |
} |
} |
} |
//main方法部分代码: |
SetPersonalFont setfont = new SetPersonalFont(); |
setfont.InitGlobalFont( new Font( "monspaced" , Font.PLAIN, 13 )); |
MainFrame main = new MainFrame(); |
main.setVisible( true ); |
中级程序员
by: 呆马 发表于:2016-06-23 18:22:06 顶(0) | 踩(0) 回复
一直想要这知识
回复评论