Java Swing JOptionPane Yes and No Button differs in font size after installing Nimbus LookandFeel

Since the font size is too small by default LookAndFeel , I used a few lines of code to set it to Nimbus , and my JOptionPane > shows a Yes and No button with different sizes. Yes, it’s still very small, and “No” - with the size that I assign to him. Does anyone know why and how to fix it?

public static void setUIFont(Font a){
    FontUIResource ax=new FontUIResource(a);
    javax.swing.UIManager.put("OptionPane.messageFont", ax);
    javax.swing.UIManager.put("OptionPane.buttonFont", ax);
    javax.swing.UIManager.put("OptionPane.Font", ax);
    javax.swing.UIManager.put("InternalFrame.titleFont", ax);
    javax.swing.UIManager.put("TextField.font", ax);
    javax.swing.UIManager.put("ComboBox.font", ax);
}

...

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); 

class UseNimBus extends SwingInvoker{
    public void run(){
        JDialog.setDefaultLookAndFeelDecorated(true);
        setUIFont(new FontUIResource(new Font(ufont, Font.PLAIN, 20)));
    }
}
(new UseNimBus()).execute();// just invokeLater()

The next line displays the options bar, but it has Yes and No with different sizes. Is this normal or is it just my problem?

inputValuex=JOptionPane.showConfirmDialog(
    myWin, "Are you exiting?", "You clicked X", JOptionPane.YES_NO_OPTION);

Update

Still not working. I tried to use the code

javax.swing.UIManager.put("OptionPane.isYesLast", true);

"", . , , boolean.

, UIManager.getDefaults(), optionpane, , 20. Yes .

+5
2

JButton Button.font.

, .

javax.swing.UIManager.put("Button.font", ax);

, , .

+4

, , , , , rootPane. , [ ], - UIResource.

, ,

  • OptionPaneUI , UIManager "OptionPane.buttonFont"
  • SynthButtonUI [ ], UIResource

- ( , / Nimbus),

UIManager.put("\"OptionPane.button\"[Default].font", ax);
UIManager.put("OptionPane:\"OptionPane.button\"[Default].font", ax);

, / UIR-. Hackaround UIRsource,

public static void setUIFont(Font a){
    // force usage of the button font as set by optionPaneUI
    // by _not_ making it a uiResource
    UIManager.put("OptionPane.buttonFont", a);
    // use uiResource for others
    FontUIResource ax=new FontUIResource(a);
    UIManager.put("OptionPane.messageFont", ax);
    ...
}

. , JOptionPane.create, .

+3

All Articles