java Swing UI设置统一字体大小

编写一个遍历组件设置字体大小的方法

java 复制代码
public static void setUIFont() {
        Font f = new Font("宋体", Font.PLAIN, 18);

        String names[] = {
                "Label", "CheckBox", "PopupMenu", "MenuItem", "CheckBoxMenuItem", "JRadioButtonMenuItem", "ComboBox", "Button",
                "Tree", "ScrollPane", "TabbedPane", "EditorPane", "TitledBorder", "Menu", "TextArea", "OptionPane", "MenuBar", "ToolBar",
                "ToggleButton", "ToolTip", "ProgressBar", "TableHeader", "PanelList", "ColorChooser", "PasswordField", "TextField",
                "TableLabel", "Viewport", "RadioButtonMenuItem", "RadioButton", "DesktopPane", "InternalFrame"
        };
        for (String item : names) {
            UIManager.put(item + ".font", f);
        }
    }

一定要在组件前调用,否则看不到效果

效果展示

相关推荐
VimorphTech1 小时前
每批开 4 个线程,为什么限制不住 TTS 的总并发?
java·spring boot·spring
Pniubi1 小时前
Java为什么要分堆和栈
java·开发语言
杨凯凡1 小时前
Spring Boot 缓存一致性怎么保证?@Cacheable、@CacheEvict 与事务提交时机实战
java·spring boot·spring cache·后端开发·缓存一致性
Rain的Java大神之路2 小时前
国家数据集团校招、社招都开了:总部雄安,这些技术岗值得认真看看
java·后端·面试
吴名氏.2 小时前
Java转AI Agent教程(第九周)错误矩阵
java·人工智能·矩阵·ai agent
文丑颜不良啊2 小时前
LeetCode1901~1920题目解析
java·leetcode
tealcwu3 小时前
【Unity基础】为什么游戏需要物理按键映射?从 Unity Input Manager 到跨引擎输入设计
java·游戏·unity
vipxieliang3 小时前
Spring Boot 性能优化实战:从启动加速到运行时调优
java·spring boot
AI全栈学习助手3 小时前
告别“转圈等待”:Spring Boot + SSE 让大模型像 ChatGPT 一样流式输出
java·人工智能·spring boot·后端·aigc