开发者

Disable Word wrap in JTextPane

开发者 https://www.devze.com 2022-12-15 18:27 出处:网络
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 w

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

精彩评论

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

关注公众号