更改JMenuBar的字体 [英] Changing a JMenuBar's font

查看:216
本文介绍了更改JMenuBar的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置JMenuBar的字体时遇到问题.我个人不喜欢Java框架默认使用的粗体字体,因此我尝试通过使用以下内容来更改它:

I have problems with setting the font of a JMenuBar. I personally don't like the bold font Java frames use by default, so I tried to change it by using something like this:

public class MyFrame extends javax.swing.JFrame {
    public MyFrame() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.setFont(new Font("sans-serif", Font.PLAIN, 12));
        setJMenuBar(menuBar);
        setSize(600, 400);

        // add some menus to the menu bar
        menuBar.add(new JMenu("Foo"));
        menuBar.add(new JMenu("Bar"));
        menuBar.add(new JMenu("Baz"));
        menuBar.add(new JMenu("Qux"));

        setVisible(true);
    }
}

据我所知,行menuBar.setFont(...)设置组件menuBar使用的字体.但是,当我实例化这些框架之一时,即使将字体的大小设置为30,默认字体也没有任何改变.

As far as I know, the line menuBar.setFont(...) sets the font used by the component menuBar. But when I instantiated one of these frames, the default font didn't change at all, not even when I put the font's size to 30.

我对此表示感谢.

推荐答案

您可以尝试为每个JMenu设置字体,也可以更改默认字体:

You can either try setting the font for each JMenu or change the default:

Font f = new Font("sans-serif", Font.PLAIN, 12);
UIManager.put("Menu.font", f);

这篇关于更改JMenuBar的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆