I would like to change the button text color of one of the options of a JOptionPane dialog to be different from the default color in Java Swing. So far, I've found some answers on how to do this for the entire application, but no answers for how to do this for one specific button.
The way I'm displaying the dialog (documentation here):
JOptionPane.showOptionDialog(
null, // parent
"Body text",
"Title text",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
null, // icon
new String[]{"Continue", "Cancel"},
"Cancel");
I would like the "Continue" button to have red text color instead, but want all other JOptionPane button text colors in my app to remain the same.
I figured it out - simply use HTML formatting to set the button text color:
JOptionPane.showOptionDialog(
null, // parent
"Body text",
"Title text",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
null, // icon
new String[]{"<html><font color=#ff0000>Continue</font></html>", "Cancel"},
"Cancel");