Disable Word wrap in JTextPane
I can开发者_Go百科't find an easy way to turn off word wrap in a JTextPane. I can't use JTextArea because I need different colors for different text. I have these big ugly lines that get uglier with word wrap turned on.
JTextArea has a setLineWrap() method, but I can't find it for JTextPane. Why?
Okay, I found an easy solution. Put the JTextPane into the center of a JPanel with a Border layout. Then, put the JPanel into a JScrollPane.
So, the hierarchy looks like this:
- JScrollPane
- JPanel (w/ Border Layout)
- JTextPane
JScrollPane contains everything below it and the JTextPane is inside of everything above it.
I'm not sure why this works, but it does.
精彩评论