0

So in JAVA, given that a Container can also be called as a component. Why cant i put a JFrame(Container) inside another JFrame(Container/component)?

  • A JFrame is supposed to be a top-level container (at the root of the containment hierachy). Why do you want to nest them? – Thilo Jan 22 '15 at 12:20
  • i don't want to nest them i was just checking can a we put a container inside another container or does it depend on hierarchy. –  Jan 22 '15 at 12:22
  • Related: http://stackoverflow.com/questions/17287248/jframe-inside-another-jframe and http://stackoverflow.com/questions/6891868/placing-jframes-inside-jframes – Thilo Jan 22 '15 at 12:22
  • so lower level containers can be placed inside upper level containers hierarchy wise ? –  Jan 22 '15 at 12:25

1 Answers1

0

Yes, you can put a container inside of another container.

That is extremely common, one of the core principles of the component/container hierarchy and quite essential to build any kind of non-trivial UI.

However

  • every component can have only one (direct) container. If you add it to a second one, it will be removed from its original container.

  • JFrame is a top-level container. It cannot be contained in other containers.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • so lower level containers can be placed inside upper level containers hierarchy wise ? –  Jan 22 '15 at 12:26
  • Not sure what "lower level" means. Placing a container (such as a JPanel) inside of another container (such as a second JPanel) makes up the "level" in the containment hierarchy, doesn't it? – Thilo Jan 22 '15 at 12:28