Reputation: 145
The problem is:
When I print the text from JTextArea
to the console:
System.out.println(textArea.toString());
I get output like this:
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?
Upvotes: 0
Views: 82
Reputation: 324108
System.out.println(textArea.toString());
That displays the properties of the text area, not the text in the text area.
Most Objects in Java has a custom toString()
method to display information about the properties of the Object.
You want:
System.out.println(textArea.getText());
Upvotes: 2
Reputation: 4592
Use the getText()
method to get the displayed text, not toString()
.
Upvotes: 1