【发布时间】:2017-05-02 14:29:52
【问题描述】:
我一直试图将一个大字符串显示为警报,但没有成功。
public void customAlert(String header, String body, ButtonType customBtn) {
clearAlert();
alert.setHeaderText(header);
//alert.setContentText(body);
String content = "";
int counter = 1;
int y=0;
for (int x = 0; x < body.length(); ++x) {
// System.err.println("concat");
if (x > counter * 50 && body.charAt(x) == ' ') {
// System.err.println("concat");
++counter;
for (; y < x; ++y) {
content.concat(Character.toString(body.charAt(y)));
}
content.concat(Character.toString('\n'));
// System.err.println(content);
}
}
alert.getDialogPane().setContent(new Label(content));
alert.getDialogPane().setMaxWidth(500);
if (customBtn != null) {
alert.getButtonTypes().clear();
alert.getButtonTypes().add(customBtn);
}
alert.showAndWait();
}
首先我尝试使用 setContentText() 并没有显示整个字符串。然后我使用了 alert.getDialogPane().setContent(new Label(body)); - 但警告框变得比屏幕尺寸更宽。然后我尝试过滤添加换行符的字符串并将 maxWidth 设置为警报,但过滤不起作用。
【问题讨论】:
-
使用来自here的异常对话框。