JOption Dialog and color...

S

sanna

Hi,

In a part of my program I am openeing an error warnign as following:

if (myVal != yourVal) {

JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);

}

But I need that message "WARNING: \n MyVal does NOT yourVal" printed
out in red color. and currently its printing in black. Any suggestions?

Thanks,

ecoswiss
 
V

Vova Reznik

sanna said:
Hi,

In a part of my program I am openeing an error warnign as following:

if (myVal != yourVal) {

JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);

}

But I need that message "WARNING: \n MyVal does NOT yourVal" printed
out in red color. and currently its printing in black. Any suggestions?

Use HTML.
 
O

Oliver Wong

sanna said:
Hi,

In a part of my program I am openeing an error warnign as following:

if (myVal != yourVal) {

JOptionPane.showMessageDialog(null,"WARNING: \n MyVal does NOT
yourVal.","Error Dialog",JOptionPane.ERROR_MESSAGE);

}

But I need that message "WARNING: \n MyVal does NOT yourVal" printed
out in red color. and currently its printing in black. Any suggestions?

Parts of Swing allow you to use HTML. I haven't tried it with
JOptionPane, but I suppose it's worth a shot.

<code>
JOptionPane.showMessageDialog(null,"<font color='#FF0000'>WARNING: \n MyVal
does NOT yourVal.</font>","Error Dialog",JOptionPane.ERROR_MESSAGE);
</code>

Alternatively, you could manually create a dialog, and put in a JLabel
set to whatever color you want. See
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDialog.html#JDialog()

- Oliver
 
V

Vova Reznik

Oliver said:
Parts of Swing allow you to use HTML. I haven't tried it with
JOptionPane, but I suppose it's worth a shot.

<code>
JOptionPane.showMessageDialog(null,"<font color='#FF0000'>WARNING: \n MyVal
does NOT yourVal.</font>","Error Dialog",JOptionPane.ERROR_MESSAGE);
</code>

Alternatively, you could manually create a dialog, and put in a JLabel
set to whatever color you want. See
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDialog.html#JDialog()

- Oliver
Or :)
UIManager.put("OptionPane.messageForeground", Color.RED);
After using that you'd better set Color back to its original.

Or ...
 
S

sanna

Or :)
UIManager.put("OptionPane.messageForeground", Color.RED);
After using that you'd better set Color back to its original.

Or ...

Using
UIManager.put("OptionPane.messageForeground", java.awt.Color.red);

I get message: Cannot resolve symbol
symbol: variable UIManager

Do I need to defien it somewhere?
Using html chanegs the color but font size and style is totally
changed from other dialog messages......
Which looks a bit funny....
any suggestions?

Thanks a lot!
 
V

Vova Reznik

sanna said:
Using
UIManager.put("OptionPane.messageForeground", java.awt.Color.red);

I get message: Cannot resolve symbol
symbol: variable UIManager

Do I need to defien it somewhere?
Using html chanegs the color but font size and style is totally
changed from other dialog messages......
Which looks a bit funny....
any suggestions?

Thanks a lot!

You'd better to use HTML, but
javax.swing.UIManager
 
I

IchBin

sanna said:
Using
UIManager.put("OptionPane.messageForeground", java.awt.Color.red);

I get message: Cannot resolve symbol
symbol: variable UIManager

Do I need to defien it somewhere?
Using html chanegs the color but font size and style is totally
changed from other dialog messages......
Which looks a bit funny....
any suggestions?

Thanks a lot!
You need this import

import javax.swing.UIManager;



--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top