I'm trying to make the menu bar items and the items of the items bigger and smaller, I've seached here a bit before (so don't mark this as repeated please) and none of the posts I've found are working.
I've tried the following codes without success:
Font f = new Font("sans-serif", Font.PLAIN, 12);
UIManager.put("menuBar.font", f);
And
menuBar.setFont(new Font(menuBar.getFont().getFontName(), menuBar.getFont().getStyle(), 12));
And this is my code where I'm trying to edit the font:
private class foo{
private JMenu mnArchivo;
private JMenuBar menuBar;
menuBar = new JMenuBar();
frmAdministracinHospital.setJMenuBar(menuBar);
JRadioButtonMenuItem rdbtnmntmGrande = new JRadioButtonMenuItem("Grande");
rdbtnmntmGrande.addActionListener(new MiGrandeActionListener());
rdbtnmntmGrande.setIcon(new ImageIcon(PrincipalWindow.class.getResource("/presentacion/fontbig.png")));
buttonGroup.add(rdbtnmntmGrande);
mnTamanoFuente.add(rdbtnmntmGrande);
private class MiGrandeActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Font f = new Font(menuBar.getFont().getFontName(), menuBar.getFont().getStyle(), 12);
UIManager.put("Menu.font", f);
}
}
Any clue please?
That's because there's not
"menuBar.font"
key in theUIManager
class, it should be:i.e. Caps are important or:
for each
JMenuItem
's fontHere's a list of these properties
Also related: Changing a JMenuBar's font
EDIT: Added mcve
I don't see where it's not working, if I run this code, it works fine for me
Before changing font:
After changing font:
The code I added above is called: Minimal, Complete and Verifiable Example, next time, please post a valid one, the same I did, so we can copy-paste, I didn't use an
actionListener
because the question isn't related to the actions, but the font. OrIcon
because it's not related either, I did a full example code that you can copy-paste and see how it works, without modifying anything, that's what you were asked for.For the
MenuBar
font you need to call:And for the
MenuItem