java.awt.font letter spacing
Asked Answered
A

1

11

Is it possible to increase letter spacing when using java.awt.font ? Something like this:

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);
Alfred answered 5/11, 2012 at 9:59 Comment(0)
O
19

You can derive a new font, with an updated tracking attribute:

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);
Olivier answered 5/11, 2012 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.