为什么我的JTextArea没有添加到我的String中的换行符?

问题描述 投票:-1回答:1

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

enter image description here

picture of unformatted text

//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;
    }
java swing jtextarea line-breaks
1个回答
2
投票

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

这告诉我你可能正在使用JTextField,而不是JTextArea

如果您需要更多帮助,请发布适当的“MCVE”。你之前已经被要求过。

© www.soinside.com 2019 - 2024. All rights reserved.