如何在警报中自动显示详细信息?

How to show automatically the details in alert?

我创建了一个类型为 INFORMATION 的警报。然后我创建了一个 TextArea 并使用 GridPane 添加到警报中。现在我的问题是如何自动显示警报的详细信息?

    Alert alert = new Alert(AlertType.INFORMATION);
    alert.setTitle("TODO Liste");
    alert.setContentText("Alle TODO's in der Liste:");
    alert.initStyle(StageStyle.UTILITY);

    TextArea textArea = new TextArea();

    GridPane content = new GridPane();
    content.setMaxWidth(Double.MAX_VALUE);
    content.add(textArea, 0, 0);

    alert.getDialogPane().setExpandableContent(content);
    alert.showAndWait();

编辑:

屏幕截图

您设置的是可扩展内容,而不是内容!因此,将您设置 Alert 内容的行更改为:

alert.getDialogPane().setContent(content);