我测试了此代码以在多行上显示字符串:
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 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/