更改默认的JLabel字体 [英] Changing default JLabel font
本文介绍了更改默认的JLabel字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为所有JLabel
实例设置默认字体.而不是分别为每个JLabel
设置字体.
How would I go about setting the default font for all JLabel
instances. Instead of setting the font for each JLabel
independently.
推荐答案
使用 UIManager
定义JLabel的默认字体:
Use UIManager
to define JLabel's default font:
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class LabelFont {
public static void main(String[] args) {
Font oldLabelFont = UIManager.getFont("Label.font");
UIManager.put("Label.font", oldLabelFont.deriveFont(Font.PLAIN));
JFrame f = new JFrame("LabelFont Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout());
JLabel df = new JLabel("Default JLabel font");
f.getContentPane().add(df);
JLabel ef = new JLabel("Font explicitly set");
ef.setFont(oldLabelFont);
f.getContentPane().add(ef);
f.pack();
f.setVisible(true);
}
}
通过: http://coding.derkeiler.com/Archive/Java/comp.lang.java.help/2005-04/msg00395.html
这篇关于更改默认的JLabel字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文