Hey there
I have a String which contains multiple lines ("\n") and I want to add it to a JDialog window. The thing is, the JDialog isn't wrapping around the text so some longer lines in the String will just run off the edge.
I there any way I can get the JDialog to resize itself so it fits the whole String into it?
JLabels don't break at new lines. Instead split the String on line breaks and add multiple JLabels. You'll have to set the layout manager correctly for them to be displayed below each other.
my impression has been that they do resize to fit the String. maybe the newlines are confusing it. be patient and someone will know for sure
SCJP
Meshulam Silk
Greenhorn
Joined: Feb 12, 2012
Posts: 21
posted
0
I actually had a look into JLabels because of they wrap but I couldn't get them to show on top of each other, they just went side by side. Do you know which layout I should use? I tried a couple I found online but none did it.
Randall: I thought so too but no, they just run off. Also it's not THAT urgent.
labels support html, just change \n's to br's (wrapped in tags)
Meshulam Silk
Greenhorn
Joined: Feb 12, 2012
Posts: 21
posted
0
I saw this too and tried it out. The problem with it is that the second line will align to the first line and won't be centered if it's a different length.
Also it trims the string so I can't put in spaces or tabs to nudge it. Is there a way to do this maybe?