问题描述
在CSS中,有一个 letter-spacing 属性,我们可以用来增加单词中每个字母的间距。
是否可以增加字母空间或文本空间?我希望可以增加字段中文本的空间。
解决方法
这里是一个例子:
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);
});
}
结果: