且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Java Swing GUI 中设置字母间距?

更新时间:2023-01-03 23:24:46

这是一个例子:

public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
        JLabel label = new JLabel("This is a text.");
        Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
        attributes.put(TextAttribute.TRACKING, 0.5);

        label.setFont(label.getFont().deriveFont(attributes));
        JOptionPane.showMessageDialog(null, label);
    });
}

结果: