首页 > 编程语言 >Java一次性设置窗口中所有组件的字体

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

时间:2022-11-01 21:11:33浏览次数:62  
标签:font Java int component 字体 组件 Font changeFont


声明:该方法参考自 ​​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);
}


标签:font,Java,int,component,字体,组件,Font,changeFont
From: https://blog.51cto.com/u_15856491/5814979

相关文章