Basically, the question says it all, I want to add a new line every...40-50 chars for a string which I never know how big it is exactly. Thank you for the help
Asked
Active
Viewed 67 times
0
-
Take a look at [this example](http://stackoverflow.com/questions/14737810/jlabel-show-longer-text-as-multiple-lines/14738193#14738193). I'd be less worried about setting the limit and simply allowing the UI to make decisions for you... – MadProgrammer Jun 01 '13 at 01:34
1 Answers
1
wrap the text in <html> </html>
and then use .setMaximumSize
and it should work
Since your do not wish to change the maximum size of the label, Try it in the HTML
jLabel1.setText("<html><body width=200>some reallly long string some reallly long string some reallly long string some reallly long string some reallly long string some reallly long string some reallly long string some reallly long string some reallly long string</body></html>");
where
width=200
relates to 200 pixels wide

exussum
- 18,275
- 8
- 32
- 65
-
s you're saying I should do string s = ""+ text + "" and then setMaximumSize in the panel? – Ted Jun 01 '13 at 01:24
-
1
-
1Apply a preferred/maximum/minimum size to any component is no recommended. It's to easy to be ignore or changed... – MadProgrammer Jun 01 '13 at 01:33
-
1There are ways to fix it. You could also set a body width inside the html. The max will not be ignored, and if you want to fix it over ride the class and call it final – exussum Jun 01 '13 at 01:37
-
So then what should I do MadProgrammer? basically, I want to limit it to a space, and it to keep having new lines each time it reaches the limit – Ted Jun 01 '13 at 01:37
-
1The easiest way would to be as i said, wrap in HTML and set the max size, if your worried about someone over riding your max, Then you should override jlabel and make the dimensions fixed. – exussum Jun 01 '13 at 01:39
-
1@User2189708 The question really is, why? You could simply use a non-editable text area instead – MadProgrammer Jun 01 '13 at 03:05