Java Can';我看不到菜单栏

Java Can';我看不到菜单栏,java,jmenubar,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 Sout

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

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);

合成是私有的JMenuBar,很可能是因为您没有向这个菜单栏添加任何内容


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

添加
菜单栏是不够的。您应该将其附加到当前的
JFrame
对象。
还要确保你正在添加一些菜单项

例如:

frame.setJMenuBar(theJMenuBar);
frame.setJMenuBar(theJMenuBar);