2012-11-05 16 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