2017-05-05 29 views
0

的問題是: 當我打印文本從JTextArea到控制檯:爲什麼從JTextArea中(搖擺)控制檯打印錯誤文本

System.out.println(textArea.toString()); 

我得到的輸出是這樣的:

javax.swing.JTextArea[,0,0,522x170,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,[email protected],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] 

任何人都可以幫助我糾正這個問題嗎?

回答

2
System.out.println(textArea.toString()); 

顯示文本區域的屬性,而不是文本區域中的文本。

Java中的大多數對象都有一個自定義的toString()方法來顯示有關對象屬性的信息。

你想:

System.out.println(textArea.getText()); 
+0

謝謝@camickr。它工作成功。 –

1

使用getText()方法獲取顯示的文本,而不是toString()

+0

感謝@kevin。真的很感激它。有效。 –

相關問題