Peter Penzov
Peter Penzov

Reputation: 1658

How to display text on several lines in TextArea

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?

Upvotes: 2

Views: 5581

Answers (1)

O.Badr
O.Badr

Reputation: 3121

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

Upvotes: 3

Related Questions