换行符“\ n”在TextField java中 [英] Newline "\n" in TextField java
问题描述
我正在构建字符串(3个不同的对象)并且在字符串的末尾我在控制台中打印时放了换行符
我得到了预期但是当我在文本字段中使用setText时,我得到一行显示,是有没有办法在文本字段中获取换行符?
I am building string ( 3 different objects ) and at the end of string I put a newline when I print in console I get what expected but when I use setText in the textfield I get one line displayed, Is there a way to get the newline in textfield?
while (itr.hasNext())
tx += "\n"+el.getnombre() + " " +other+"\n";
System.out.println(tx);
textfield.setText(tx);
推荐答案
JTextField或TextField(不确定您使用的是哪个) )仅适用于单行。如果您想要一个基本的多行文本显示,并且您正在使用Swing,那么请使用JTextArea。如果你没有使用Swing,那么请告诉我们你正在使用哪个GUI库,因为这是你的问题应该提到的一个重要细节。
JTextField or TextField (not sure which you're using) are for single lines only. If you want a basic multiline text display and you're using Swing, then use a JTextArea. If you're not using Swing, then please tell us which GUI library you are using as this is an important detail that your question should mention.
这篇关于换行符“\ n”在TextField java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!