title: Java- Write Text onto Image, then Write to Output File
body: <p>I have an image on top of which I would like to write text that has multiple lines, is center-aligned, and dynamic (variable width). I've tried using the <code>drawString</code> method from <code>Graphics</code>, but I could not get the centering and dynamic positioning to work. I'm currently poking around in the <code>swing</code> library with <code>JLabels</code> and such, but I'm having difficulty with finding a relatively simple approach to this. I would also like to have the final image written to a file, but it seems that mixing <code>ImageIO</code> with <code>JPanel</code>s is not working very well.. I'm getting just a black box at the moment.. If anyone could provide even a simple outline of how to approach this, I would greatly appreciate that.</p>
  
  <p>Thank you!</p>
  
  <hr>
  
  <p>Sorry, I should have been more specific.. I would like the text itself to be center-aligned (as in the middle of each row should line up), rather than having the text be placed in the center of the image. The text will be placed in some other location on the image, not in the middle. Again, I apologize for the unclear descriptions. Thanks!</p>