-1 java user-interface swing jtextfield
在 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);
});
}
Run Code Online (Sandbox Code Playgroud)
结果: