I put a JTextArea on mu gui.But i can't print multiple lines on that?Why is that?.I have created a Item class and then created an Item object array in my gui.Then i print it on my jTextArea.This is my code i have put in my button.

jTextArea2.setText("Item Name"+"  |  "+"Price"+"  |  "+"Item Number");
        for(int i=0;i<4;i++){

Recommended Answers

You are using setText(...), which replaces any existing text. Try append(...) instead

Jump to Post

All 2 Replies

As JamesCherrill said, use the append() function to insert strings into your textArea. setText() sets the text area to whatever String you provide, much like opening a file in "w" or in "a+" mode.

jTextArea2.setText("Item Name"+"  |  "+"Price"+"  |  "+"Item Number\n"); //clears the text area and inserts the header
for(int i=0;i<4;i++)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.