public class TextRenderer {
public static void main(String[] args) {
JLabel label = new JLabel("<html><p align=\"center\">text text text text text text text");
label.setOpaque(false);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBounds(0,0,100,100);
JFrame frame = new JFrame();
frame.setSize(100, 100);
frame.setLayout(null);
frame.add(label);
BufferedImage image = new BufferedImage(100,100,BufferedImage.TYPE_INT_ARGB);
SwingUtilities.paintComponent(image.createGraphics(), label, frame, new Rectangle(image.getWidth(),image.getHeight()));
try {
ImageIO.write(image, "png", new File("bild.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}