JLabel does not show a long paragraph

String Text

Window

How can I enable JLabel to display the entire paragraph?

+3
source share
4 answers
JLabel label = new JLabel("<html>"+test+"</html>");
+8
source

The component is JLabelcommonly used for short snippets of text. If you need to drop a large number of texts, you should use JTextArea. After that, you can wrap the text using setLineWrap :

Sets the line wrapping policy in the text area. If set to true, the lines will be wrapped if they are too long to fit in the selected width.

If you still want to use JLabel (not recommended), setting the label size should do the trick for you.

+5
source

html br-, . Swing html-.

:.

"<html>" + "a line" + "<br />" + 
"second line" + "</html>";
+2
source

Try surrounding the entire line with an HTML p tag like this:

String text = "<html><p>This program........ BIG LINE_HERE....called person.txt</p></html>";
JLabel info = new JLabel(text);
+1
source

All Articles