I was wondering what's the significance of setHelpMenu(Menu m) method of MenuBar class. RHE book says it should display the help menu in the right hand side of all the other menus. But when you try this code -
The menu named menu2 is at second position, which does not make method setHelpMenu() any different from add() method of MenuBar. Only if it is the last call, then the menu is set to the right, but that can be achieved with add() method as well. Any other advantages of using setHelpMenu() ? TIA, - Manish
I've experienced the same problem. What is weird is that the Menu class holds the help menu in a different reference than it holds the normal menus. All menus are stored in a Vector while the Help menu is stored in a Menu reference in order to treat it differently. What I've seen, though, is that on certain platforms the same code behaves differently. That is, sometimes the menu is added to the right of the menubar and sometimes not. This has nothing to do with when you invoke setHelpMenu(). You can invoke the latter method whenever you want to. The help menu will (should) be added on the right-most position (or on the left-most depending on the locale). My guess is that if it does not, then it must be the the look & feel that doesn't support that feature. I'll look into that.
Moreover, pay attention to what follows. setHelpMenu() in java.awt.MenuBar does not really behave as expected and setHelpMenu() in javax.swing.JMenuBar is not implemented at all and will throw an error at runtime if invoked... What a shame! (Bug 4087846) The following code has no functionality but shows the concept:
The execution yields:
Swing is not a SCJP2 objective, but this is good to know anyway. [ March 17, 2002: Message edited by: Valentin Crettaz ]