2012-11-05 106 views
8

使用java.awt.font時可以增加字母間距嗎? 事情是這樣的:java.awt.font字母間距

Font font = new Font("serif", Font.PLAIN, 21); 
//Increase the spacing - perhaps with deriveFont()? 

BufferedImage image = new BufferedImage(400, 600, BufferedImage.TYPE_INT_RGB); 
Graphics2D graphics = image.createGraphics(); 
graphics.setFont(font); 
graphics.drawString("testing",0,0); 

回答

10

你可以得到一個新的字體,用更新的跟蹤屬性:

Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>(); 
attributes.put(TextAttribute.TRACKING, 0.5); 
Font font2 = font.deriveFont(attributes); 
gr.setFont(font2); 
gr.drawString("testing",0,20); 
+0

謝謝,沒有的伎倆! – user1031054