Dim*_*ims 0 java javafx messagebox controlsfx
我读过这个:http://code.makery.ch/blog/javafx-dialogs-official/
我不认为40行代码可以显示简单的异常消息对话框.
那么,如何在JavaFX中显示对话框?可能是ControlsFX可以帮忙吗?
UPDATE
比较它在Swing中的完成方式:
JOptionPane.showMessageDialog(frame,
"Eggs are not supposed to be green.",
"Inane error",
JOptionPane.ERROR_MESSAGE);
Run Code Online (Sandbox Code Playgroud)
它是
一
线
的
码
这绰绰有余.
您只需要创建一个新的Alert,其内容设置为a的TextArea内部ScrollPane,然后将您的异常文本添加到TextArea
Exception e = new Exception("An exception!!!!!!!!!!!!!!!!!");
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("An exception occurred!");
alert.getDialogPane().setExpandableContent(new ScrollPane(new TextArea(sw.toString())));
alert.showAndWait();
Run Code Online (Sandbox Code Playgroud)
更新以匹配OP的更新:
JavaFX中的Swive示例中的equivelant是:
new Alert(Alert.AlertType.ERROR, "This is an error!").showAndWait();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12816 次 |
| 最近记录: |