I normally program in MS VFP (Visual FoxPro) and have for most of the last twenty years. I'm new to Java. In VFP we normally have a main menu (the programmer controls the menu via the program) and the menu prompts can be changed along with any submenus, also after selecting a menu item the selected item can be turned off (disabled). In general VFP would match a JDesktop enviroment. However, it appears that JDesktop is not the recommended way of setting up a windows (thick client/application) program. So if I decide to use JFrames as independent windows how does one control the menu that activates the new window? I'd first like to disable the menu prompt and then change the rest of the menu prompts (some call them pads) along with their submenus. What I think I want is a JFrame with a menu that is the controling menu. Imagine an accounting program that had a menu with "Ledgers", "System", "Exit". "Ledgers" has a submenu that contains "Account Recieveable", "Accounts Payable", "General Ledger". If I select "General Ledger" from the "Ledgers" submenu I want the Menu to change to "Ledgers", "Transactions", "Reports", "Maintanence". If I choose a different selection say "Acconts Payable" again the menu would change. And of course the selected menu item would be disabled in "ledgers". Anyway you get the idea. So far I have not found anything that allows me to change the menu from a new JFrame (one opened from the menu). I at first thought I could call the parent but found that it did not work (could be I'm doing something wrong). Thanks in advance for any help or examples.
I understand when you say you want one controlling menu that launches new JFrames and have the menuitems become disabled when you launch the new frame. For this you would do something like this -
I don't understand the part about the menus changing... you could do something similiar as in the above code, add or remove menu items of a menu in the listener when something is selected, but I don't see why you would want to change the menus in the "main" frame when you could just add the specific menus to the new frame.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Dec 20, 2003
Boy thank you, I really thought I wasn't going to get an answer. As far as the controling menu changing I think your right - there is no reason the new JFRAME can't have a menu and of course that new menu would only control the functions associated with JFrame (i.e. accounts payable functions). But it adding the new menu by passes the real question - how do I control the parent from the child JFrame? I have attempted to pass the 'this' to the child JFrame and control the parent menu without sucess. Again thanks for taking the time. John
Actually, it probably actually is working when you add and remove menus in other frames... it's just that you have to make sure and call "validate()" and "repaint()" on the JMenuBar so that it redraws itself with the new components on it. The code below shows something close to what you originally asked for, a main frame that launches child frames, and the child frames add menus to the parent. Especially note the "setMenuEnabled()" method in the ChildFrame class.
Joined: Dec 20, 2003
Thanks again.... I happy becausing I was begining to think there was not way to change a JMenu in a JMenuBar. John