java - 看不到菜单栏

标签 java jmenubar

我编写的代码不显示菜单栏,知道我应该做什么吗?

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//What happens on close.
this.setSize(1100, 750);//Initial size of the frame.

menuBar = new MenuBar();

east = new EastPanel();
central = new CentralPanel();
south = new SouthPanel();

//Add the menu bar to the frame.
this.setJMenuBar(menuBar.getComposition()); 

//Frame's other components.
this.add(central.getCentralPanel());
//this.add(msBoard.getMessagesBoard(), BorderLayout.SOUTH);
this.add(east.getEastPanel(), BorderLayout.EAST);
this.add(south.getSouthPanel(), BorderLayout.SOUTH);
//this.add(menuBar);
//Load the card images.
//cards = new CardImages();
//cards.loadCards();

//Initialize cardsPerPlayer list.
//cardsPerPlayer = new ArrayList<ImagePanel>();

this.setVisible(true);

其中 getComposition 是

public JMenuBar getComposition(){
    return this.Composition;
}

并且Composition是私有(private)的JMenuBar

最佳答案

添加 MenuBar 还不够。您应该将其附加到当前的 JFrame 对象。
还要确保您向其中添加了一些菜单项。

示例:

frame.setJMenuBar(theJMenuBar);

关于java - 看不到菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21307628/

相关文章:

java - 向后读取二进制文件

java - Redis中的notify-keyspace-events是什么

java - 如何获取一个(int)数组的元素的所有可能组合?

java - 带工具栏和菜单栏的网格包布局

java - 维护 Java 应用程序配置文件的最佳方法

java - 如果主键不为空,则 Spring 数据 JPA 不允许保留实体

java - Java 1.8 中无法正确显示 Swing 应用程序菜单名称

java - 如何使用 JMenuItem 将另一个类调用到我的主菜单类?

java - 面板内绘制的图像似乎有错误的 x,y 偏移

Java - 是否可以在 JMenuBar 的最右侧添加 JMenu?