mbreen
mbreen

Reputation: 558

Java Swing g.drawString Word Wrap

I am working on a small little panel popup that displays a few values. Basically when the player lands on a chance spot the game draws a card that does a few actions. On the physical card panel I have a paint method with a drawString which draws the description of the card. Because the card is small in width, the description tends to draw off the edge of the card. Is there any way to make a word wrap so the description doesn't run off the edge of the card?

Upvotes: 0

Views: 1789

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

See LabelRenderTest.java. It uses a JLabel, which can not only render multi-line text, but also formatted text. In this example we render it to a BufferedImage, that is then drawn to the UI.

Upvotes: 1

Related Questions