2014-01-23 85 views
0

我寫的代碼不顯示菜單欄,有什麼想法我該怎麼辦?看不到菜單欄

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

和寫作是私人的JMenuBar

回答

1

Propably因爲您didint添加任何東西到這個menubar

在eclipse中,當我添加菜單欄(使用生成器)沒有任何項目,我沒有看到它,但我菜單添加到菜單後它將工作。

1

添加MenuBar是不夠的。您應該將其附加到當前的JFrame對象。
另外請確保您正在添加一些菜單項。

實施例:

frame.setJMenuBar(theJMenuBar);