Web Development

General discussion


Changing Fonts & Font Color, JOptionPane

By hamant5 ·
Can anyone help me change the Fonts & Color of my Texts.....?
import java.io.*;
import java.util.Random;//needed for generating random number
import java.applet.Applet;//used for display of applet windows
import java.awt.Color;//adding colour
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
import java.awt.Font;

public class Guesses extends java.applet.Applet
public static void main(String[] args) throws IOException
Random generator = new Random();//generator represents random number
int number;
number = generator.nextInt(100) + 1;
int guess=number;
String myNumber;//from JOptionPane
String DataEntry;
String challenge="Try to guess the number I'm thinking of!";
String challenge2=challenge+Color.RED;
String high="too high - guess again:";
String low="too low - guess again:";
String correct1="Finally you got it out! You only took ";
String correct2=" tries to get the correct number ";

JOptionPane.showMessageDialog( null, challenge2,"Today's Challenge: ",

int myInt;
BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
boolean found=false;

for(int i=1;(!found);i++)
DataEntry = JOptionPane.showInputDialog( "Type your number here:" );

if (guess<myInt)
JOptionPane.showMessageDialog(null, high,"Today's Challenge: ",

else if
JOptionPane.showMessageDialog(null, low,"Today's Challenge: ",

else {
JOptionPane.showMessageDialog(null, correct1+i+correct2+number,
"Today's Challenge: ",

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Martin Simons In reply to Changing Fonts & Font Col ...

Swing components can use html in labels (which
JOptionPane also uses, so try this:

String bogus = "<FONT COLOR=\"RED\" FACE=\"ARIAL\" SIZE=\"5\">rest of string</FONT>"

replacing the colors, faces, and sizes to what you need/want.

Collapse -

by Martin Simons In reply to

should be

bogus = ">FONT COLOR=\"#66FF33\" FACE=\"Arial\" SIZE=\"5\"<rest of string>/FONT<"

Collapse -

by Martin Simons In reply to

oops got the greater than and less than backwards in the last comment, but you get the idea.

Collapse -

it is for About item

by melancholyJ In reply to Changing Fonts & Font Col ...

how can i put Font Style in this code?
JOptionPane.showMessageDialog(TestMenu.this,"This is a sample of Menus where you can access all the MenuItem ","About",JOptionPane.PLAIN_MESSAGE);

Related Discussions

Related Forums