I'm trying to create a complete menubar using multidimensional ararys.
So far I have this code:
private JMenuBar menuBar = new JMenuBar();
private JMenuItem[][] menuItem = new JMenuItem[5][5];
private String[] menuBarItemNames = {"File", "Edit", "Database", "View", "Help"};
private String[] menuBarFileItemNames = {"Save", "Refresh", "Next", "Previous","Exit"};
view() {
setJMenuBar(menuBar);
for(int u = 0; u < menuItem.length; u++){
menuItem[u][0] = new JMenu(menuBarItemNames[u]);
for(int t = 0; t < menuBarFileItemNames.length; t++){
//Code to add 'File' child items to the 'File' MenuBarItem
}
menuBar.add(menuItem[u][0]);
}
I'm struggling to figure out how to add the menuBarFileItems to the File menu.
I have this code to add to the second for loop:
menuItem[0][t] = new JMenuItem(menuBarFileItemNames[t]);
but it just causes the first item on the menuBar to be replaced by 'Save'.
Any ideas?
Also, is it not possible to have private JMenuItem[][] menuItem = new JMenuItem[5][];
so that I don't have to set the size of each menuBar item, e.g. File = 5 items, Edit = 5 items etc
Thanks