是否有人设法使用换行符(\ n,\ r)字符在JFace ErrorDialog中显示详细错误消息?
我正在尝试将StackTrace显示为详细消息,但它只显示在一行中
StringBuffer sbStackTrace = new StringBuffer();
for (StackTraceElement ste : throwable.getStackTrace()) {
sbStackTrace.append(ste.toString()).append('\n');
}
final IStatus status = new Status(IStatus.ERROR, pluginId, statusMsg, new Throwable(sbStackTrace.toString(), throwable));
ErrorDialog dialog = new ErrorDialog(shell, "Error", customMessage, status, IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR)
打开ErrorDialog会显示我想要的内容,但详细消息格式不正确。
有什么想法吗?
答案 0 :(得分:1)
查看source for ErrorDialog.java中的ErrorDialog.populateList(List, IStatus, int, boolean)
方法,对话框看起来每行只包含一个IStatus
,但如果IStatus
有子项,则会包括他们在后续的路线上。因此,您需要构建MultiStatus
对象或创建自己的IStatus
实现。
答案 1 :(得分:0)
答案 2 :(得分:0)
为了实现相同目的,还可以构建MultiStatus。 MultiStatus可以将下一个IStatus作为子节点,因为详细区域中的ErrorDialog每行显示一个IStatus,您将得到相同的结果。
中的诀窍答案 3 :(得分:0)
使用包含stacktrace作为消息的new来包装Exception。