My Main
class extends JFrame
and for some reason, I can't get my MenuBar
and items to show correctly. Is there a special way of adding the menubar?
public class Main extends JFrame
{
// DRIVER
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main window = new Main();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private JMenuBar menuBar;
private JMenu menu,
menuFile;
private JMenuItem menuItemNew,
menuItemExit;
...
// CONSTRUCTOR
public Main()
{
initializeWindow();
initializeMenu();
}
private void initializeWindow()
{
setTitle(TITLE + " " + VERSION);
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setBackground(Color.DARK_GRAY);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
backgroundColor = new GradientBackground(WINDOW_WIDTH, WINDOW_HEIGHT);
}
private void initializeMenu()
{
// Menubar
menuBar = new JMenuBar();
menuBar.setBounds(0, 0, WINDOW_WIDTH, 72);
menuBar.setBackground(Color.LIGHT_GRAY);
menuBar.setVisible(true);
setJMenuBar(menuBar);
// Menu title
menu = new JMenu();
menu.setForeground(Color.BLACK);
menuBar.add(menu);
// File Option
menuFile = new JMenu("FILE");
menuFile.setForeground(Color.BLACK);
menuFile.setBackground(Color.DARK_GRAY);
menuBar.add(menuFile);
// New File
menuItemNew = new JMenuItem("New");
menuItemNew.setForeground(Color.BLACK);
menuItemNew.setBackground(Color.DARK_GRAY);
menuFile.add(menuItemNew);
// New File
menuItemExit = new JMenuItem("Exit");
menuItemExit.setForeground(Color.BLACK);
menuItemExit.setBackground(Color.DARK_GRAY);
menuItemExit.setEnabled(true);
menuFile.add(menuItemExit);
getContentPane().add(menuBar);
} // END initializeMenu()