javafx-2 - 如何在TextArea中显示多行文本

标签 javafx-2 javafx javafx-8

我测试了此代码以在多行上显示字符串:

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");

但结果我只得到字符串data。在 JavaFX 中多行显示字符串的正确方法是什么?

最佳答案

使用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");

关于javafx-2 - 如何在TextArea中显示多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17122435/

相关文章:

JavaFx 应用程序在退出时崩溃

css - 在 JavaFX CSS 中设置 BackgroundImage 路径的正确方法

css - 使用像 FireBug 这样的工具调试 JavaFx

java - 在 JavaFX 中制作视频(媒体)播放器占用尽可能多的空间,但不能超过

javafx - 从 getValue() 和 setValue() 函数之外的 Delegated Property 中获取 KProperty 信息

JavaFX 8设置TextArea大小未满

java - Intellij 封装 JavaFx 应用程序

storage - 支持 Javafx 2.x 中的离线存储

java - 如何在 fxml 项目中使用很棒的字体 (javafx)

java - 使用 JavaFX 的窗口内的棋盘