java - ArrayList of type Object to display output in JTextArea -
i have assignment i'm working in college, have gui asking input user , display final output (an arraylist of type object) in jtextarea, in separate classes. problem it's displaying return tostring() method overwritten. here's code, tostring method in non gui class:
@override public string tostring() { int u = 1; system.out.println("team " + name + " has " + players.size() + " players"); for(int i=0; i< players.size();i++) { system.out.print(u++ + "."); system.out.println(players.get(i)); } return "team " + name + " has " + size + " players"; } }
this jtextarea calling gui class:
public class gui extends team { //buttons /constructor public gui() { frame = new jframe("team manager"); frame.setlayout(new borderlayout()); frame.setsize(300, 300); jta = new jtextarea(super.tostring()); frame.add(jta, borderlayout.center); }
only return value of tostring() displaying in jtextarea, how make displays loop line line? have tried making foreach loop , appending results, tried settext() , append() don't take type objects, how should go doing this?
( myobject o : arraylist1) { textarea1.append( o.tostring() ); }
if want separate text lines use textarea.setlinewrap(true);
also don't use settext()
said @sha33. know method change text in jtextarea. use append
method. if want separate text can append \n
@ end of each line.
also can @ articles:
Comments
Post a Comment