I'm wondering if there is a way to make text wrap around when it reaches the end of a frame? When using the drawString method, if a line of text exceeds the length of the frame, it seems to just continue on and not wrap around. Does anyone know a way around this?
Asked
Active
Viewed 33 times
1 Answers
0
JTextArea
would probably suit. It displays text and you can set setLineWrap(true)
.
Wrapping text within a frame is a more complicated behavior than can/should be developed as a single method. For example, when you exceed the pre-assigned vertical area, what should happen? And what size of frame is required for layout?
For all these reasons, "display text wrapping in a frame" should be (and is) a component. That component is JTextArea.

Thomas W
- 13,940
- 4
- 58
- 76
-
1That worked perfectly, thank you. Also, in case anyone reads this, you should use setWrapStyleWord(true) as well so that it wraps at each word rather than each letter. – Shaun Feb 16 '14 at 15:51