Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing the contents of arraylist in JTextArea

 
Bishawjit Dey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an arraylist of string type and I want to print the contents of that arraylist in a jtextarea using its settext method. but jTextArea only accepts string Objects.
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
What about the toString() method?
 
Bishawjit Dey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you

I have my arraylist in a separate class from the gui class and I am trying to set the text in Jtextarea with a method. kind of like this

JTextArea txt = new JTextArea();

txt.setText(cal.returnArray());

returnArray is a method which will return a few variables packed in an ArrayList of string type

I am confused as how I can typecast a method to toString().
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, he is talking about using the toString() method in the Arraylist.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this should do the work:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic