I am trying to add a subclass of JMenuBar to a user interface but for some reason it never shows up. I have tried using JFrame.setJMenubar() and JFrame.add(), i have tried adding it from within a SwingUtilities.invokeLater() call etc... It still worked when in was using JMenuBar itself instead of a subclass so i suspect it has something to do with that.
This is the code that initializes the application window:
public DramaSimWindow() {
initializeSelf();
initializeContainers();
this.setVisible(true);
}
private void initializeSelf() {
initializeContentPane();
this.setBounds(100, 100, 800, 500);
this.setJMenuBar(new DramaSimMenuBar());
this.setResizable(false);
}
This is the subclass of JMenuBar which is located inside the main window class as a private class:
private class DramaSimMenuBar extends JMenuBar {
private static final long serialVersionUID = 1L;
public DramaSimMenuBar() {
initializeSelf();
}
private void initializeSelf() {
menuBar = new JMenuBar();
initializeFileMenu();
initializeEditMenu();
}
private void initializeFileMenu() {
JMenu fileMenu = new JMenu("File");
fileMenu.add(new JMenuItem("New"));
fileMenu.add(new JMenuItem("Open"));
fileMenu.add(new JMenuItem("Save"));
fileMenu.add(new JMenuItem("Save as"));
fileMenu.add(new JMenuItem("Exit"));
menuBar.add(fileMenu);
}
private void initializeEditMenu() {
JMenu editMenu = new JMenu("Edit");
editMenu.add(new JMenuItem("Copy"));
editMenu.add(new JMenuItem("Cut"));
editMenu.add(new JMenuItem("Paste"));
menuBar.add(editMenu);
}
}