简体   繁体   English

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

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

So i have this code, which opens a JOptionPane with information about the exception: 所以我有这段代码,它将打开一个有关异常信息的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));

The only thing i am not happy with is the fact that its all the same color, so i thought why not change the color of the Strings regarding the exception to red. 我唯一不满意的是所有颜色都相同,因此我想为什么不将Strings的颜色更改为红色。 So i googled a bit and found several similar question on SO, and also tried what they suggested there with html-tags and such, but i was not successful. 所以我在Google上搜索了一下,发现了几个类似的问题,并尝试使用html-tags这样的建议,但是我没有成功。 Is there any working way to color the text? 有什么可行的方法为文本着色? Currently it looks like this with html tags 目前,它看起来像这样用HTML标签

The entire string needs to be enclosed within the HTML tags. 整个字符串需要包含在HTML标记内。 For more information, see How to Use HTML in Swing Components. 有关更多信息,请参见如何在Swing组件中使用HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM