为什么控制台从JTextArea(Swing)打印错误文本 [英] Why the console prints error text from the JTextArea (Swing)
本文介绍了为什么控制台从JTextArea(Swing)打印错误文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是:
当我将文本从JTextArea
打印到控制台时:
The problem is:
When I print the text from JTextArea
to the console:
System.out.println(textArea.toString());
我得到这样的输出:
javax.swing.JTextArea[,0,0,522x170,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@43413332,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],colums=0,columWidth=0,rows=0,rowHeight=0,word=false,wrap=false]
有人可以帮助我纠正此问题吗?
Can anyone help me to rectify this problem?
推荐答案
System.out.println(textArea.toString());
这将显示文本区域的属性,而不是文本区域中的文本.
That displays the properties of the text area, not the text in the text area.
Java中的大多数对象都有一个自定义的toString()
方法,用于显示有关对象属性的信息.
Most Objects in Java has a custom toString()
method to display information about the properties of the Object.
您想要:
System.out.println(textArea.getText());
这篇关于为什么控制台从JTextArea(Swing)打印错误文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文