PDA

View Full Version : Text Color in Java Dialogs



DBQ
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.

patrickballeux
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 :

mycomponent.setForeground(java.awt.Color.BLUE);


Hope it helped!

Patrick

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

patrickballeux
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.

Zugzwang
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.

Reiger
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.