JavaFX Alert truncates the message? [duplicate]

我是研究僧i 提交于 2020-01-23 01:00:22

问题


I noticed that if I try to show an Alert with a long message, it tends to get truncated (at a word boundary).

Example:

import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Stage;

public class AlertTest extends Application {
    @Override
    public void start(final Stage primaryStage) throws Exception {
        new Alert(AlertType.INFORMATION, "this is a pretty long message that "
                + "should not be truncated in this alert window, no matter "
                + "how long it is").showAndWait();
    }

    public static void main(final String... args) {
        launch(args);
    }
}

This only displays "this is a pretty long message that should not be truncated" here.
What is the reason for the truncation, and how can I avoid it?

I'm using Oracle JDK 1.8.0_60 in Linux.


回答1:


I think it's only a Windows and Linux issue. It doesn't happen on MacOS. However I think this will fix it for you on all platforms.

Alert alert = new Alert(AlertType.INFORMATION);
alert.setContentText("this is a pretty long message that "
                + "should not be truncated in this alert window, no matter "
                + "how long it is");
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.showAndWait();



回答2:


Try as

Alert alert = new Alert(AlertType.INFORMATION);
alert.getDialogPane().setContent( new Text("this is a pretty long message that "
                + "should not be truncated in this alert window, no matter "
                + "how long it is"));
alert.showAndWait();


来源:https://stackoverflow.com/questions/33318661/javafx-alert-truncates-the-message

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