How can I enable the JLabel to show the whole paragraph?
Asked
Active
Viewed 9,810 times
5
-
1try this [jlabel wrap](http://stackoverflow.com/questions/2420742/make-a-jlabel-wrap-its-text-by-setting-a-max-width) – PresleyDias May 07 '12 at 07:46
4 Answers
5
The JLabel
component is usually used for short pieces of text. If you need to throw in large amounts of texts, you should use the JTextArea
. Once you use that, you can then wrap the text using the setLineWrap:
Sets the line-wrapping policy of the text area. If set to true the lines will be wrapped if they are too long to fit within the allocated width.
If you still want to go ahead with the usage of a JLabel (not recommended), setting the size of the label should do the trick for you.

npinti
- 51,780
- 5
- 72
- 96
3
Put the text in html tags and use br-tags to break the line. Nearly every Swing component does support html text.
E.G.:
"<html>" + "a line" + "<br />" +
"second line" + "</html>";

Stephan
- 4,395
- 3
- 26
- 49
2
Try to surround the whole string with an HTML p tag as follows:
String text = "<html><p>This program........ BIG LINE_HERE....called person.txt</p></html>";
JLabel info = new JLabel(text);

Mario Freitas
- 21
- 1