英文:
How to set letter spacing in Java Swing GUI?
问题
Sure, here's the translation:
在CSS中,有一个letter-spacing属性,我们可以用它来增加单词中每个字母的间距。
有没有一种方法可以增加字母间距或文本间距?我希望我可以增加字段中文本的间距。
英文:
In CSS, there is a letter-spacing property that we can use to increase spacing per letter in a word.
Is there a way I can increase a letter space or text space? I was hoping I can increase the space of the text in a field.
答案1
得分: 8
这是一个示例:
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JLabel label = new JLabel("这是一段文本。");
Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
attributes.put(TextAttribute.TRACKING, 0.5);
label.setFont(label.getFont().deriveFont(attributes));
JOptionPane.showMessageDialog(null, label);
});
}
结果:
英文:
Here is an example:
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);
});
}
Result:
专注分享java语言的经验与见解,让所有开发者获益!
评论