2011-10-19 38 views
1

我有一個圖形用戶界面我想添加一個菜單欄,但每次我嘗試添加JmenuBar時都會說它期望java.awt.menubar,並且找到了一個java.swing.Jmenubar,它就是它應該檢測。這是我的代碼。不能設置JMenuBar

class CipherGUIFrame extends JFrame{ 

    public CipherGUIFrame(){  
     super("Caesar Cipher GUI"); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setSize(400, 600); 

     Container content = getContentPane(); 
     content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));  

     JMenuBar menuBar = new JMenuBar(); 

     menu = new JMenu("File"); 
     open = new JMenuItem("Open"); 
     save = new JMenuItem("Close");   

     menu.add(open); 
     menu.add(save); 
     menuBar.add(menu); 

     setMenuBar(menuBar); // this line here is what gives me the error  
    }  
} 
+0

的方法是set'J'MenuBar。 – camickr

+0

嘗試setJMenuBar,並記住使用API​​,因爲它會告訴你所有這些,並且比我們更快。 –

+2

我很遲鈍謝謝。 – user541597

回答

3

我認爲你需要,而不是使用setMenuBar

+0

這是正確的+1 – mKorbel

2

'setJMenuBar' 你可以試試setJMenuBar(),而不是