Daxesh Prajapati
Daxesh Prajapati

Reputation: 151

how can i change color of string in Message Box?

How can i change color of String in Message Box?

String patientname="ABC";
JOptionPane.showMessageDialog(null, "Patient "+patientname+" Already Assigned");

In above code i want to change color of patientname.

Upvotes: 1

Views: 4999

Answers (2)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

JOptionPane option = new JOptionPane();
option.setFont(new Font("Arial"));//Edit this line
option.showMessageDialog(null, "Text Test");

For Specific String

JOptionPane.showMessageDialog(null, "Patient <html><font color='red'>"+patientname+"</font></html> Already Assigned");

Upvotes: 2

Mengjun
Mengjun

Reputation: 3197

You can use HTML tags and put the content into JLabel, like follows:

JOptionPane.showMessageDialog(null, new JLabel(
    "<html><h2><font color='red'>Hello</font>, world </h2></html>"));

enter image description here

Upvotes: 5

Related Questions