为什么我的 JTextArea 不在我的字符串中添加换行符?

Why does my JTextArea not add in the line breaks from my String?

我想要一个JTextArea在用户点击按钮时显示返回的文本,但是虽然实际的字符串包含换行符,但文本区域不显示它们?为什么?

//when user clicks this button//
txtPizzaOrder.setText(newPizza.getInfo());

public String getInfo(){
    String sizeString=String.valueOf(this.size);
    String rtnStment="Size: "+sizeString+"\nCrust:"+this.crust+"\nSauce: "
            +this.sauce+"\nFirst topping: "+this.topping1+"\nSecond topping: "+
            this.topping2+"\nCost: "+this.getCost()+"\n------------------------";
    return rtnStment;
    }

根据你的图片,我看到了组件中间的文本,而不是顶部。

这告诉我您可能使用的是 JTextField,而不是 JTextArea

如果您需要更多帮助 post 合适的 "MCVE"。之前已经有人要求你这样做了。