Reputation: 151
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
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
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>"));
Upvotes: 5