This is what I need in my game regarding text:
Word Wrap Support given a bounding box
Vertical and Horizontal alignment given a bounding box
Now, I've been reading about how to use TextLayout, and it seems possible to write all this myself but I'd prefer to think at a higher level. I just want a Label class with a signature like this:
public Label(String text, Alignment alignment, VAlignment vAlignment);
Does anyone know of an open source (non-gpl) library out there that makes text formatting simple?
Class Graphics2D This Graphics2D class extends the Graphics class to provide more sophisticated control over geometry, coordinate transformations, color management, and text layout. This is the fundamental class for rendering 2-dimensional shapes, text and images on the Java(tm) platform.
The Java 2D API class Graphics2D extends Graphics to support more graphics attributes and provide new rendering methods. Setting up a Graphics2D context is described in “Rendering with Graphics2D”.
If you are using java2d to paint your game graphics, you should be able to use the the awt or swing text components to render your text. You could e.g. create a JLabel and call its paint und update methods manually in your render queue with your Graphics2D context.
JLabel label = new JLabel("your text");
label.setLocation(0, 100);
label.setSize(20, 100);
label.paint(g); // g is your Graphics2D context
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With