是否可以在 JOptionPane.showMessageDialog() 中更改字符串颜色

Is it possible to change a string color in JOptionPane.showMessageDialog()

所以我有这段代码,它会打开一个 JOptionPane,其中包含有关异常的信息:

String fileName=e.getStackTrace()[0].getFileName();
String methodName=e.getStackTrace()[0].getMethodName();
String line=String.valueOf(e.getStackTrace()[0].getLineNumber());

JOptionPane.showMessageDialog(null, new JLabel("There was an unexpected "+e+" at file: "+fileName+" in method: "+methodName+" in line: "+line));

我唯一不满意的是它的颜色都是一样的,所以我想为什么不将关于异常的字符串的颜色更改为红色。所以我用谷歌搜索了一下,在 SO 上发现了几个类似的问题,还尝试了他们在那里用 html-tags 等建议的内容,但我没有成功。有没有什么工作方法可以为文本着色?目前看起来 this 带有 html 个标签

整个字符串需要包含在 HTML 标签中。 For more information, see How to Use HTML in Swing Components.