首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >看不到MenuBar

看不到MenuBar
EN

Stack Overflow用户
提问于 2014-01-23 19:39:11
回答 2查看 368关注 0票数 0

我写的代码没有显示菜单栏,你知道我应该怎么做吗?

代码语言:javascript
复制
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在哪里

代码语言:javascript
复制
public JMenuBar getComposition(){
    return this.Composition;
}

并且组合是私有的JMenuBar

EN

回答 2

Stack Overflow用户

发布于 2014-01-23 20:10:54

可能是因为您没有向此menubar添加任何内容。

在eclipse中,当我添加了菜单栏(使用builder)而没有任何项目时,我没有看到它,但是当我添加菜单到菜单栏后,它就可以工作了。

票数 1
EN

Stack Overflow用户

发布于 2014-01-23 20:12:37

仅添加MenuBar是不够的。应将其附加到当前JFrame对象。

另外,还要确保您向其中添加了一些菜单项。

示例:

代码语言:javascript
复制
frame.setJMenuBar(theJMenuBar);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21307628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档