简体   繁体   中英

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:

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. 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. Is there any working way to color the text? Currently it looks like this with html tags

The entire string needs to be enclosed within the HTML tags. For more information, see How to Use HTML in Swing Components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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