View Full Version : Text Color in Java Dialogs

September 22nd, 2008, 01:07 AM
Hi Everybody,

Does anybody know how to change the color of the text in the standard java dialog boxes?

I am referring to: JOptionPane

Can this even be done?

Thank You.

September 22nd, 2008, 01:25 AM
For all components of Swing, the obj.setForeground(Color c); will select the color to be shown. Some classes are using also obj.setColor(Color c);

An easy way is :


Hope it helped!


September 22nd, 2008, 01:29 AM
What if I wanted to change only a part of the text of the JOPTIONPANE?

September 26th, 2008, 07:26 AM
What do you mean part of it?

If you want different colors, you will have to put different components (Labels, text box, ...)

Is that what you mean?

You cannot have several color for one component.

September 26th, 2008, 09:22 AM
What if I wanted to change only a part of the text of the JOPTIONPANE?

If it is not supported, then you will need to write your own specialised JOptionPane class. Have a look at the licence of the respective class, maybe you can tweak the original source code.

September 26th, 2008, 09:48 AM
One of the key features of JOptionPane is that it takes *any* object for message argument. That means, you could write, for this specific purpose, a generic component (say, an JPanel extension) which deals with all you could possibly wish for; and pass such an object to the JOptionPane.