Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > java menus disappear

java menus disappear
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 4, 2002, 12:39 PM
 
When a new Java Swing Application project is created in project builder and it is built and run, Hello World is drawn in the window and there are menus such as file and edit in the menubar but when you go to About "app name" the menus disappear. but when you click on the main window or close the aboutbox the menus reappear.

Is there a way to keep the menus always in the menubar i.e not disappearing when other windows than the main window are foremost.


thansk
     
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Dixon, Ca
Status: Offline
Reply With Quote
Apr 7, 2002, 04:33 PM
 
Originally posted by road runner:
<STRONG>When a new Java Swing Application project is created in project builder and it is built and run, Hello World is drawn in the window and there are menus such as file and edit in the menubar but when you go to About "app name" the menus disappear. but when you click on the main window or close the aboutbox the menus reappear.

Is there a way to keep the menus always in the menubar i.e not disappearing when other windows than the main window are foremost.


thansk</STRONG>
So they cloned a sheep - who could tell the difference anyway? - Robin Williams
     
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Dixon, Ca
Status: Offline
Reply With Quote
Apr 7, 2002, 04:41 PM
 
Originally posted by road runner:
<STRONG>When a new Java Swing Application project is created in project builder and it is built and run, Hello World is drawn in the window and there are menus such as file and edit in the menubar but when you go to About "app name" the menus disappear. but when you click on the main window or close the aboutbox the menus reappear.

Is there a way to keep the menus always in the menubar i.e not disappearing when other windows than the main window are foremost.


thansk</STRONG>

Oops!

The short answer is that menu bars are added to Frames/JFrames. Since Java has no concept of "global" menu bars, Apple implemented a strategy that permits a windows menu bar to be displayed as the global menu bar when the window is frontmost. In the case of a PB Swing application the About Box window has no menu bar added to it. Compare Welcome.java to AboutBox.java and you will see that a menu bar was added to Welcome.java, but not AboutBox.java. If you want the About Box window to have a menu bar simply cut and paste the code that creates the menu bar in Welcome.java and paste it into AboutBox.java. IMPORTANT! Menu bars can not be shared across multiple windows!
So they cloned a sheep - who could tell the difference anyway? - Robin Williams
     
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 8, 2002, 02:50 AM
 
Originally posted by gandalf:
<STRONG>
If you want the About Box window to have a menu bar simply cut and paste the code that creates the menu bar in Welcome.java and paste it into AboutBox.java. IMPORTANT! Menu bars can not be shared across multiple windows!</STRONG>
thanks for the reply, yeah i tried sharing a menu class with multiple windows with strange results ... There has to be a better way than to duplicate all the code though.
     
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Dixon, Ca
Status: Offline
Reply With Quote
Apr 8, 2002, 11:50 AM
 
Originally posted by road runner:
<STRONG>

thanks for the reply, yeah i tried sharing a menu class with multiple windows with strange results ... There has to be a better way than to duplicate all the code though.</STRONG>
Well, as I said, that was the short answer! The best way I've found to "share" menus is to create Factory classes that create desired menus and menu bars. That way the code is not duplicated, although you do have to call the Factory object to create the menu for each window. The menu content itself is defined in a separate text file which is parsed and used to construct the menus. I can email you some sample code if you'd like.
So they cloned a sheep - who could tell the difference anyway? - Robin Williams
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:32 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2