Java help.... again

Discussion in 'OT Technology' started by Traynor, Jan 19, 2005.

  1. Traynor

    Traynor New Member

    Joined:
    Sep 11, 2003
    Messages:
    585
    Likes Received:
    0
    hey guys,
    does anyone know how to output an array into a jTextPane? i tried this but it doesnt work, it only outputs the last element of the array.

    Code:
     for (int i = 0; i < o.segment().length; i++) {
                    jTextPane1.setText(o.segment()[i]);
                }
    
     
  2. sam758

    sam758 OT Supporter

    Joined:
    Aug 26, 2003
    Messages:
    901
    Likes Received:
    0
    if i remember correctly, i think u need a jtextarea component or sumthing that displays multiple lines of text instead of just 1 line like in jtextpane. hope that helps.
     
  3. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    The reason it only displays the last element is because you're replacing the current text with each consecutive element. You should read all the elements into a string first, then display them:

    Code:
    String text = new String();
    
    for(int i = 0; i < o.segment().length; i++) {
    text += o.segment()[i]
    }
    
    jTextPanel.setText(text);
     
  4. Traynor

    Traynor New Member

    Joined:
    Sep 11, 2003
    Messages:
    585
    Likes Received:
    0
    hahahhahah wow, i didnt even think about that, thanks alot buddy
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Oh, and if you want each on a separate line, add:

    + "\n"

    to the line in the for loop.
     

Share This Page