Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Alert truncates the message? [duplicate]

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.

like image 206
aditsu quit because SE is EVIL Avatar asked Dec 05 '22 20:12

aditsu quit because SE is EVIL


2 Answers

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();
like image 120
David Avatar answered Jan 05 '23 20:01

David


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();
like image 41
Uluk Biy Avatar answered Jan 05 '23 19:01

Uluk Biy