如何向JTextArea添加文本? (控制台模拟) [英] How do you add text to JTextArea? (console simulation)

查看:205
本文介绍了如何向JTextArea添加文本? (控制台模拟)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JTextArea中添加文本/命令(如在控制台中)?



或者,如何在FTP程序中添加JTextArea并添加如前面添加的不可编辑文本的C:\tmp \ -list命令?

解决方案

一种可能性。您可以使用 JTextArea.append(String)方法:

  JTextArea textArea = new JTextArea 
textArea.append(Your new String);

来自JavaDoc:


将给定的文本附加到文档的末尾。


请注意,您必须自己添加换行符,例如

  textArea.append(Your new String\\\
);






b $ b




如果您想要一个真正的自制控制台,请查看 Lanterna JLine


How does one add text/commands (like in console) into JTextArea?

Or, more specifically, how can I add a JTextArea as console in my FTP program and add commands like C:\tmp\ -list with non-editable text added earlier?

解决方案

Of course there is a possibility. You can use the JTextArea.append(String) method for this:

JTextArea textArea = new JTextArea();
textArea.append("Your new String");

From JavaDoc:

Appends the given text to the end of the document.

Take care that you have to add line breaks by yourself like

textArea.append("Your new String\n");

if you want to add a new line to the end.


If you want to have a real selfmade console, look for example at Lanterna or JLine.

这篇关于如何向JTextArea添加文本? (控制台模拟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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