user3207935
user3207935

Reputation: 11

How to change font with showconfirmdialog?

I have tried many different tutorials and none have worked this is what I have. Any help?

UIManager.put("OptionPane.font", new FontUIResource(new Font("Press Start 2P", Font.PLAIN, 11)));

if (questionNumber == questions.size()) {
    triviagui.questionFrame.setVisible(false);
    JOptionPane.showMessageDialog(null, "Your score for this level was : " + levelScore + " out of 10. \n Your total score is " + triviagui.totalScore, "Scores", JOptionPane.INFORMATION_MESSAGE, pokeballIcon);
}

Upvotes: 0

Views: 708

Answers (1)

SuperRetro
SuperRetro

Reputation: 91

this is how I change my font in a JLabel, so maybe it is any help?

message = new JLabel(textMessage);

// create bigger text (to-times-bigger)
Font f = message.getFont();
message.setFont(new Font(f.getName(), Font.PLAIN, f.getSize()*2));
// put text in middle of vertical space
message.setVerticalTextPosition(JLabel.CENTER);

You just take the font from your label, and reset the font as you like. Maybe you can do the same with your JDialog?


I found a working answer here: formatting text in jdialog box

this could be a method called by the actionListener of a button:

public void openPopUp(){
        String t = "<html>The quick <font color=#A62A2A>brown</font> fox."; 
        JOptionPane.showMessageDialog(null, t);
    }

Gives you this result: enter image description here

Upvotes: 2

Related Questions