Since the font size is too small in default LookAndFeel, I used a few lines of code to set it to Nimbus, and my JOptionPane shows Yes and No button with different size. Yes is still very small, while No is set to be with the size I assign it to be. Anybody knows why or 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 following line shows the option pane but it has Yes and No with different size. Is it normal or is it just my problem?
inputValuex=JOptionPane.showConfirmDialog(
myWin, "Are you exiting?", "You clicked X", JOptionPane.YES_NO_OPTION);
Still not working. I have tried to use the code
javax.swing.UIManager.put("OptionPane.isYesLast", true);
to change the location of the Yes button but it didn't have any effect. I just wanted to see how to set those values such as boolean.
Also, I even listed all keys in UIManager.getDefaults()
which contains optionpane, or button, and their font sizes are all set to 20. The Yes button still as smaller font.
put("OptionPane. buttonFont", new Font("Arial", Font. PLAIN, 12)); Just remember to set it before any JOptionPane dialog appears.
For instance: Create a new Font from the FontFamily list, and apply it to your component with c. setFont (font); A second approach is, to search for TTF-Files (for example), and create new Fonts with the static method Font. createFont (new File ("..."));
public Example() { initUI(); } It is a good programming practice to put the code that creates the GUI inside a specific method.
The font for the JButton
is actually coming from the Button.font
property.
If I add this to your list of properties, it works.
javax.swing.UIManager.put("Button.font", ax);
Why you get two different sizes, while funny, is beyond me at this moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With