How to display text on several lines in TextArea

喜夏-厌秋 提交于 2019-12-12 17:12:38

问题


I tested this code to display strings on several lines:

TextArea dataPane = new TextArea();
        dataPane.setEditable(false);
        dataPane.prefWidthProperty().bind(hbox.widthProperty());

        dataPane.setWrapText(true);     // New line of the text exceeds the text area
        dataPane.setPrefRowCount(10);
        dataPane.setText("Testdata");
        dataPane.setText("\ndata");

But as a result I get only the String data. What is the proper way to display strings on several lines in JavaFX?


回答1:


Use TextArea.appendText

TextArea dataPane = new TextArea();
        dataPane.setEditable(false);
        dataPane.prefWidthProperty().bind(hbox.widthProperty());

        dataPane.setWrapText(true);     // New line of the text exceeds the text area
        dataPane.setPrefRowCount(10);
        dataPane.setText("Testdata");
        dataPane.appendText("\ndata");


来源:https://stackoverflow.com/questions/17122435/how-to-display-text-on-several-lines-in-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!