Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about Menu (MenuBar, PopupMenu) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about Menu (MenuBar, PopupMenu)" Watch "Question about Menu (MenuBar, PopupMenu)" New topic

Question about Menu (MenuBar, PopupMenu)

Sam Zheng
Ranch Hand

Joined: Nov 29, 2000
Posts: 61

I have been baffled by the following questions for a while:
1. What containers can have Menu? In several different
occasions, I have seen different answers. In RHE's book,
it is said that only Frame can have Menu. However, in
another occasion (forgot the name of the book I read),
it is said that all these containers (Applet, Window,
Panel) can have Menu.
2. What determine whether a container can have Menu or not?
Thanks! Sam
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
My understanding is that only Frame can have menu components.
However, for PopupMenu, you can add it to almost all the containers.
Any correction on that?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Sam, Adrian ...
I'm fairly certain Adrian is right. The Class Libraries state

The only valid parent for a MenuBar is a Frame instance.

And since Menu objects can only be inserted in MenuBar's; you can only build a Menu in a Frame.
On the other hand, a Pop-up Menu can be added to any component.
Hope that helps.

The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Sam Zheng
Ranch Hand

Joined: Nov 29, 2000
Posts: 61
Adrian and Jane, Thanks! One more question: If only Frame
can have Menu, then why all those containers (Panel, Applet,
Frame, etc) all implement MenuContainer interface? What
is this MenuContainer used for? Thanks again! Sam
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Sam,
Any component that can contain any MenuComponent has to implement MenuContainer Interface. and MenuComponent means....

Although only Frames can contain menubar but all components can contain popup menu. So Component class implements MenuContainer interface.
hope this clears your doubt.

I agree. Here's the link:
subject: Question about Menu (MenuBar, PopupMenu)
It's not a secret anymore!