• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

AWT Container

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 )
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic