只是(令人惊讶地;-)注意到应用程序在我的win6 +机器上看起来如此拥挤的原因(同样适用于Vista和Win7,都有120dpi设置,jdk6和jdk7):从桌面属性查找的控件字体都有错误的字体家庭和错误的大小:
public static void main(String[] args) {
Font guiFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty("win.defaultGUI.font");
int guiSize = guiFont.getSize();
Font iconFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty("win.icon.font");
System.out.println("gui default: " + guiFont + "\nicon default: " + iconFont);
}
Run Code Online (Sandbox Code Playgroud)
输出:
gui default: java.awt.Font[family=Tahoma,name=Tahoma,style=plain,size=13]
icon default: java.awt.Font[family=Segoe UI,name=Segoe UI,style=plain,size=15]
Run Code Online (Sandbox Code Playgroud)
后者几乎用于所有文本的本机应用程序,而Swing使用前者...
问题:
解决最后一个的选项:
编辑
万一有人感兴趣,这是肮脏的黑客:
/**
* Replaces the default gui desktop font property with the icon font
* if the former is smaller.
*
*/
public static void …Run Code Online (Sandbox Code Playgroud) 请问有没有另一种方法如何在运行时更改Font作为整个AWT/Swing GUI使用FontUIResource,没有任何知识/兴趣,如果有局部变量和JComponents的类型


import java.awt.*;
import java.awt.event.*;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
public class SystemFontDisplayer extends JFrame {
private static final long serialVersionUID = 1L;
private JFrame frame = new JFrame("Nimbus UIDeafaults and Font");
private JComboBox fontsBox;
private javax.swing.Timer timer = null;
private JButton testButton = new JButton("testButton");
private JTextField testTextField = new JTextField("testTextField");
private JLabel testLabel = new JLabel("testLabel");
public SystemFontDisplayer() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontFamilyNames = ge.getAvailableFontFamilyNames(Locale.getDefault());
fontsBox = new …Run Code Online (Sandbox Code Playgroud)