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.
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();
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With