开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜