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

查看:31
本文介绍了更改 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.

感谢您对此的任何帮助.

I appreciate any help concerning this.

推荐答案

您可以尝试为每个 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天全站免登陆