aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AWT Container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "AWT Container" Watch "AWT Container" New topic
Author

AWT Container

Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
Which cannot be added to a Container?
A. a Menu
B. a Panel
C. an Applet
D. a Component
E. a Container
Answer: A
I read somewhere else that a Menu CAN be added to a container. What goes?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Menu can be added to MenuBar or a MenuItem but as Menu do not decend from Component it can't be added to any container.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Where did you read that ?
Ask yourself of what type a Menu is (see its hierarchy) and what types can be added to a Container...


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
A Menu is a MenuComponent which is NOT the same thing as a Component.
Containers hold Components - NOT MenuComponents.
MenuContainers hold MenuComponents.
Frame can "setMenuBar" and the MenuBar can hold a Menu.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
OK, rewrite my sentences:
Menu is a MenuItem and it do not descend from Component.
Menu cannot directly be added to a Container because do not descend from Component.
But, Menu can be added to a MenuBar or another Menu. And a MenuBar can added to a Container a Frame.
And PopupMenu can be added to any Component.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Carlos,
But, Menu can be added to a MenuBar or another Menu. And a MenuBar can added to a Container a Frame.

MenuBar cannot be added to a Container, but only to a Frame !!!
(I hope it was a typo though )
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
>Containers hold Components - NOT MenuComponents.
>MenuContainers hold MenuComponents.
what are MenuContainers ?

Originally posted by Cindy Glass:
A Menu is a MenuComponent which is NOT the same thing as a Component.
Containers hold Components - NOT MenuComponents.
MenuContainers hold MenuComponents.
Frame can "setMenuBar" and the MenuBar can hold a Menu.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610

What are MenuContainer?

MenuContainer is an interface implemented by the following classes Component, Menu, MenuBar and Frame.
See theMenuContainer Interface in the API
And to answer your private message,

But Frame is a Container though

that's true but a Container is not a Frame and that's why you can't add a MenuBar to a Container.
HIH
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
mark,
please post your question here instead of sending private messages so that everybody can benefit

i had meant that we know that classes which inherit under the heirarchy
of MenuComponents like Menu, MenuItem etc cannot be added to Components
as their heirarchy is different.
fine, but then suddenly there are exceptions like MenuBar can be added to
Frame, or PopMemu can be added to any Component. so can you tell me what
interface or which method they have or implement or what is it that makes
them apart.
i hope u got my point. I have drawn two heirarchy digrams one for
Component and the other for MenuComponent and the special conditions for
MenuBar and PopupMenu is bothering me. In the sense that i want to why ?

You are right there are two distinct hierarchies, one for Components and one for MenuComponents.
A MenuBar can only be added to a Frame because only that class has a setMenuBar method taking a MenuBar as argument.
PopupMenu can be added to any Component.
From Java AWT: Popup Menu

...
Popup menus can be attached-to/removed-from any component, using the methods in class java.awt.Component:
-add(PopupMenu popup)
-remove(MenuComponent popup)
Note that a popup menu can only be owned by one component at a time.
...

I hope that helps clear your doubt...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT Container