在JTextPane中禁用Word换行 [英] Disable Word wrap in JTextPane

查看:131
本文介绍了在JTextPane中禁用Word换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到一个简单的方法来关闭JTextPane中的自动换行。我不能使用JTextArea,因为我需要不同的颜色用于不同的文本。我有这些丑陋的线条,开启自动换行更加丑陋。

I can'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有一个setLineWrap()方法,但我找不到JTextPane。为什么?

JTextArea has a setLineWrap() method, but I can't find it for JTextPane. Why?

推荐答案

好的,我找到了一个简单的解决方案。将JTextPane放入具有Border布局的JPanel的中心。然后,将JPanel放入JScrollPane。

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(带边框布局)

  • JTextPane

JScrollPane包含它下面的所有内容,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.

这篇关于在JTextPane中禁用Word换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆