How to set letter spacing in Java Swing GUI?

huangapple go评论78阅读模式
英文:

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);
    });
}

结果:

How to set letter spacing in Java Swing GUI?

英文:

Here is an example:

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

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

Result:

How to set letter spacing in Java Swing GUI?

huangapple
  • 本文由 发表于 2020年8月14日 19:24:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63411840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定