在多行上将文本追加到JTextArea吗? [英] Append Text to JTextArea on Multiple Lines?

查看:92
本文介绍了在多行上将文本追加到JTextArea吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个数字的字符串,打印出来时看起来像这样:

I have a string with multiple numbers, when printed out it looks something like this:

2
4
5
10
20
25
50

2
4
5
10
20
25
50

但是,当我将字符串追加到JTextArea时,它看起来像这样:

However, when I append the string to a JTextArea it looks like this:

24510202550

24510202550

如何使JTextArea看起来像带有单独行中数字的输出?谢谢!

How can I make the JTextArea look like the ouput with the numbers on seperate lines? Thanks!

推荐答案

您可能正在使用System.out.println()打印到控制台. System.out.println()将为您在每行的末尾添加'\n'字符.

You're probably using System.out.println() to print to console. The System.out.println() will add '\n' character to the end of each line for you.

但是要以相同的方式将字符串输出到JTextArea,请使用jTextArea.append('\n');.

But to output strings to JTextArea in same way use jTextArea.append('\n');.

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

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