文本在JTextArea之外 [英] Text goes outside JTextArea

查看:115
本文介绍了文本在JTextArea之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用Java做一些事情,这要求我在ScrollPane中有一个JTextArea。

I am trying to do something in Java which requires me to have a JTextArea in a ScrollPane.

以下是我如何定义它们:

Here is how I have defined them:

private JTextArea longestparagraph = new JTextArea();

....
JScrollPane scrollpanedreapta = new JScrollPane(longestparagraph, 
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
                        JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollpanedreapta.setBorder(BorderFactory.createTitledBorder("Cel mai lung paragraf:"));

我遇到的问题是文本在到达新行时没有开始TextArea的右边框,但它仍在继续。有任何想法如何解决?这是一张让我的陈述更清晰的图片。

The problem I'm encountering is that the text doesn't start on a new line when it reaches the right border of the TextArea but it continues. Got any ideas how to solve that? Here's a picture to make my statement a little bit clearer.

推荐答案

找到答案。不得不这样:

Found the answer. Just had to this:

longestparagraph.setLineWrap(true);
longestparagraph.setWrapStyleWord(true);

这篇关于文本在JTextArea之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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