如何更改 Java Swing 组件的默认字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17122135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 01:03:47  来源:igfitidea点击:

How to change the default font size of Java swing components

javaswingfontsawtuimanager

提问by u2488528

When doing Java JFrame design, I need to edit the font size and font type manually each time drag and drop from the Swing palette. The default font of Java Swing components is Tahoma 11 plain.

在进行 Java JFrame 设计时,每次从 Swing 调色板拖放时,我都需要手动编辑字体大小和字体类型。Java Swing 组件的默认字体是 Tahoma 11 plain。

What I want is the font size and font type to be set to Tahoma 15 plain when I drag JTextfieldand then JLabel. So I don't need to change manually anymore.

我要的是字体大小和字体类型,当我拖到设置为宋体15平JTextfield,然后JLabel。所以我不再需要手动更改了。

采纳答案by Andrew Thompson

Adjusting the UIDefaultsis one way. Another is to design a pluggable look & feel.

调整UIDefaults是一种方法。另一个是设计可插拔的外观

回答by sithum

This is not a netbeans platform problem. Use the UIManager class to set the Font for the whole program. Hope these links will help you.

这不是 netbeans 平台问题。使用 UIManager 类为整个程序设置字体。希望这些链接对您有所帮助。

Setting the Default Font of Swing Program

设置 Swing 程序的默认字体

Setting the Global Font for a Java Application

为 Java 应用程序设置全局字体