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?
Asked
Active
Viewed 1,764 times
0
-
One way: display it in a JTextArea with its wrap properties turned on. You can make the background color null if desired and make it non-editable to make it not look textarea-ish. – Hovercraft Full Of Eels Feb 04 '12 at 18:31
-
Alright, that's probably my best bet at this point. Thanks! – mbreen Feb 04 '12 at 18:38
-
You're welcome. There are other ways such as using a JLabel and HTML text formatted by style sheets (I think that's what they're called). – Hovercraft Full Of Eels Feb 04 '12 at 18:40
1 Answers
1
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.

Community
- 1
- 1

Andrew Thompson
- 168,117
- 40
- 217
- 433