Text goes outside JTextArea

放肆的年华 提交于 2019-12-02 14:59:33

问题


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:"));

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.


回答1:


Found the answer. Just had to this:

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


来源:https://stackoverflow.com/questions/14074549/text-goes-outside-jtextarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!