0
点赞
收藏
分享

微信扫一扫

Java一次性设置窗口中所有组件的字体

十里一走马 2022-11-01 阅读 131
java


声明:该方法参考自 ​​codeday​​ ,作者 codeday; 下面结合此方法逻辑写的代码为原创。

下面只为类中部分必要代码:

//所用方法
public void changeFont(Component component, Font font){
component.setFont(font);
if (component instanceof Container)
{
for (Component child : ((Container)component ).getComponents())
{
changeFont(child, font);
}
}
}

public WindowLog(String s, int x ,int y, int w, int h) {
setLayout(new FlowLayout());
init(s);
setLocation(x, y);
setSize(w, h);
Font f = new Font("宋体", Font.PLAIN, 20); //创建字体对象
changeFont(this, f); //将当前窗口和字体对象传入
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}


举报

相关推荐

0 条评论