Javafx 将滚动条添加到警报中
在这种情况下,我必须在javafxJavafx 将滚动条添加到警报中,javafx,scrollbar,alert,Javafx,Scrollbar,Alert,在这种情况下,我必须在javafxAlert public static Optional<ButtonType> showAlertDialog(AlertType type, String title, String content) { TextArea textArea = new TextArea(content); textArea.setEditable(false); textArea.setWrapText(true); GridP
Alert
public static Optional<ButtonType> showAlertDialog(AlertType type, String title, String content) {
TextArea textArea = new TextArea(content);
textArea.setEditable(false);
textArea.setWrapText(true);
GridPane gridPane = new GridPane();
gridPane.setMaxWidth(Double.MAX_VALUE);
gridPane.add(textArea, 0, 0);
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setContentText(content);
return alert.showAndWait();
}
公共静态可选showAlertDialog(AlertType类型、字符串标题、字符串内容){
TextArea TextArea=新的TextArea(内容);
textArea.setEditable(false);
textArea.setWrapText(true);
GridPane GridPane=新建GridPane();
gridPane.setMaxWidth(Double.MAX_值);
添加(textArea,0,0);
警报警报=新警报(类型);
警报。设置标题(标题);
alert.setContentText(内容);
返回警报。showAndWait();
}
当字符串大小超过屏幕大小时,我无法读取字符串的隐藏部分,我如何才能将
滚动条添加到警报当前,您没有将文本区域或网格窗格添加到警报。你创造了它们,却什么也不做;相反,您只需设置警报的contentText
。您需要将内置滚动功能的文本区域添加到警报中
一种方法是设置DialogPane.content
属性,而不是contentText
属性
private Optional<ButtonType> showAlert(AlertType type, String title, String content) {
Alert alert = new Alert(type);
alert.setTitle(title);
TextArea area = new TextArea(content);
area.setWrapText(true);
area.setEditable(false);
alert.getDialogPane().setContent(area);
alert.setResizable(true);
return alert.showAndWait();
}
目前,您没有将文本区域
或网格窗格
添加到警报
。你创造了它们,却什么也不做;相反,您只需设置警报的contentText
。您需要将内置滚动功能的文本区域添加到警报中
一种方法是设置DialogPane.content
属性,而不是contentText
属性
private Optional<ButtonType> showAlert(AlertType type, String title, String content) {
Alert alert = new Alert(type);
alert.setTitle(title);
TextArea area = new TextArea(content);
area.setWrapText(true);
area.setEditable(false);
alert.getDialogPane().setContent(area);
alert.setResizable(true);
return alert.showAndWait();
}
执行对话框:执行对话框: