I am using html to make text in a JLabel span multiple lines. However if I enter a long string with no spaces it doesn't go onto a new line and instead causes an underlying JScrollpane to display a horizontal scrollbar and pushs the components to the right of the JLabel out of the view area. So anyone know if it is possible to word wrap strings without spaces in a JLabel?
Asked
Active
Viewed 875 times
0
-
2What is the content of this 'long string with no spaces', DNA coding strings? – Andrew Thompson Mar 22 '12 at 09:55
-
It matters to make me care enough to think about the question or offer an answer. Never mind. – Andrew Thompson Mar 22 '12 at 11:01
-
1Dont worry Einstein a guy has already given me an answer below. – csss Mar 22 '12 at 11:08
1 Answers
5
You can use a JTextArea
for that purpose:
JTextArea ta = new JTextArea();
ta.setEditable(false);
ta.setLineWrap(true);
ta.setOpaque(false);
ta.setWrapStyleWord(false); // This makes wrapping on char boundaries, and I think is the default value

Guillaume Polet
- 47,259
- 4
- 83
- 117