Home Tutorial Java Swing Set text color in JoptionPane

 
 

Share on Google+Share on Google+
Set text color in JoptionPane
Posted on: November 24, 2009 at 12:00 AM
Advertisement
In this section, you will learn how to set text color in JOptionPane.

Set text color in JoptionPane

In this section, you will learn how to set text color in JOptionPane. Now to do this, we have used UIManager class which is responsible for look and feel. Using following key value pair, we have set the text color for JOptionPane and background color for JPanel:

um.put("OptionPane.messageForeground", Color.red);
um.put("Panel.background", Color.yellow);

Here is the code:

import java.awt.*;
import javax.swing.*;

public class SetColor {
	public static void main(String[] args) {
		UIManager um = new UIManager();
		um.put("OptionPane.messageForeground", Color.red);
		um.put("Panel.background", Color.yellow);
		JOptionPane.showMessageDialog(null,"Hello","Set Color",
				JOptionPane.INFORMATION_MESSAGE);
	}
}

Output

Advertisement

Related Tags for Set text color in JoptionPane :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 24, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com