Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know of a java2d text library?

Tags:

java

text

java-2d

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?

like image 365
Daniel Kaplan Avatar asked Jun 13 '09 19:06

Daniel Kaplan


People also ask

How does Graphics2D work?

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.

What is the Java API that used in a graphics 2D?

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”.


1 Answers

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
like image 65
Daniel Seidewitz Avatar answered Sep 18 '22 15:09

Daniel Seidewitz