Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make font bold in java dialogue box?

Tags:

java

fonts

swing

I have this:

JOptionPane.showMessageDialog(null, " " + company1 + 
            " Has Higher A Market Value\nThan " + company2,
                "Information", JOptionPane.INFORMATION_MESSAGE);

I want to make company1 and company2 appear bold in the dialogue box. I tried using html formatting but (I suppose) obviously that did not work.

Any clues or hints?

TIA!

like image 952
JavaN00b Avatar asked Jan 22 '11 16:01

JavaN00b


People also ask

How do I make my font bold in Java?

To make a text bold create a font bypassing FontWeight. BOLD or, FontWeight. EXTRA_BOLD as the value of the parameter weight and, to make a text italic pass FontPosture. ITALIC as the value of the parameter posture.

How do I make my fonts bold?

Type the keyboard shortcut: CTRL+B.


1 Answers

Use HTML

JOptionPane.showMessageDialog(null, "<html> <b> Has </b>Higher A Market Value</html> ");

If your default font doesn't support it then you can specify it like

 String msg = "<html>This is how to get:<ul><li><i>italics</i> and "
        + "<li><b>bold</b> and "
        + "<li><u>underlined</u>...</ul></html>";
        JLabel label = new JLabel(msg);
        label.setFont(new Font("serif", Font.PLAIN, 14));
        JOptionPane.showConfirmDialog(null, label);  

Output:

alt text

like image 79
jmj Avatar answered Sep 20 '22 12:09

jmj