简体   繁体   English

如何减少java.awt.font中的字母间距?

[英]How do I decrease letter spacing in java.awt.font?

I'm trying to make a graph with a numbered axis. 我正在尝试制作带有编号轴的图形。 However, I can't seem to decrease the spacing between these numbers. 但是,我似乎无法减少这些数字之间的间隔。 Here is the current code I am using to decrease the spacing between the numbers in my paintComponent method, but it doesn't seem to work: 这是我用来减小paintComponent方法中数字之间的间距的当前代码,但是它似乎不起作用:

super.paintComponent(g);

Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
attributes.put(TextAttribute.TRACKING, 0.5);

Font font = new Font("Monospaced", Font.PLAIN, 1);
Font font2 = font.deriveFont(attributes);

g.setFont(font2);

When the numbers are displayed, the space between them is the same as before. 显示数字时,它们之间的间隔与以前相同。

I've tried reducing the 0.5 in the attributes.put() method, but it doesn't seem to reduce the spacing. 我尝试在attributes.put()方法中减小0.5,但似乎并没有减小间距。 I've also tried TextAttribute.KERNING and using TextAttribute.KERNING_ON , but that didn't work out either. 我也尝试了TextAttribute.KERNING并使用TextAttribute.KERNING_ON ,但这也不起作用。

Any help is greatly appreciated! 任何帮助是极大的赞赏!

Thanks :) 谢谢 :)

From TextAttribute.TRACKING JavaDoc : 从TextAttribute.TRACKING JavaDoc

Tracking values are typically between -0.1 and 0.3; 跟踪值通常在-0.1至0.3之间; values outside this range are generally not desireable. 通常不希望超出此范围的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM