Formatting Strings in TextField JavaFX

时间:2017-06-15 10:30:57

标签: string javafx textfield

In my JavaFX application I am trying to format a String and then push it to TextField.

This is my code:

String result = "No of Rows Returned : " + repairHeaderEntities.size();

            if(null!=repairHeaderEntities && repairHeaderEntities.size()>0){
                result = result + "\n" + "\nRepair Status Code: "+entity.getRepairStatusCode();

analyzeResult.setText(result);

analyzeResult is the TextField fx id.

But in the output I am getting the following:

No of Rows Returned : 1Repair Status Code: ENDE

As you can see there output is not moving to a new line and is coming up in the same line.

1 个答案:

答案 0 :(得分:1)

来自documentation for TextField

  

文本输入组件,允许用户输入无格式文本的单行。与之前版本的JavaFX不同,对多行输入的支持不是TextField控件的一部分,但这是TextArea控件的唯一目的。

使用TextArea代替TextField

如果您不希望用户能够编辑文本控件中的文本,您也可以考虑使用Label