File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Menus and replacing the prompts fr JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Menus and replacing the prompts fr JFrame" Watch "Menus and replacing the prompts fr JFrame" New topic
Author

Menus and replacing the prompts fr JFrame

John Fabiani
Greenhorn

Joined: Dec 20, 2003
Posts: 9
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.


John Fabiani
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, John!
I'm moving this to the Swing / JFC / AWT forum where folks just love to talk about this GUI stuff...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
John Fabiani
Greenhorn

Joined: Dec 20, 2003
Posts: 9
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.

John Fabiani
Greenhorn

Joined: Dec 20, 2003
Posts: 9
Thanks again.... I happy becausing I was begining to think there was not way to change a JMenu in a JMenuBar.
John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Menus and replacing the prompts fr JFrame
 
Similar Threads
Menu Problems
Too many methods
Applets And JDesktop Panes
Method X not found in class Y error
Creating one class from another