我注意到,如果我尝试用长消息显示Alert
,它往往会被截断(在单词边界处)。
示例:
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);
}
}
此处仅显示“这是一条不应被截断的非常长的消息” 截断的原因是什么,我该如何避免呢?
我在Linux中使用Oracle JDK 1.8.0_60。
答案 0 :(得分:8)
我认为这只是一个Windows和Linux问题。它不会发生在MacOS上。不过,我认为这将在所有平台上为您解决。
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();
答案 1 :(得分:3)
尝试
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();