Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can JPanels contain JPanels? Swing hierarchy question.

198 views
Skip to first unread message

Martin Lau

unread,
Sep 27, 2000, 3:00:00 AM9/27/00
to
Hi there,

Is there a limit to the number of windows within windows you can have? I
want to have a number of similar frames (each containing a graphics area and
a text area) laid out in a container, which is in turn housed in a larger
window, that has a menu bar, and which also house a separate window. I
realise that I can have a JFrame as the large outer window, and as many
JPanels as I like within that, but can a JPanel within a JFrame contain
futher discreet windows (such as other JPanels)which have their own
components, such as the frame mentioned above?


Many thanks,

Martin


Gamma

unread,
Sep 27, 2000, 3:00:00 AM9/27/00
to


JPanels can certainly nest quite deep. This is in fact a common
practice used by designers to make complex layouts using just the
simple ones (Border-, Grid-, Flow-) plus some spit and polish.

I don't know what the theoretical limit on panel nesting is, though.

Keep in mind that when you say "window", some may interpret that as
java.awt.Window, which is a generic top-level beast, as opposed to
java.awt.Container, which is a generic Component which may contain
sub-Components. (JPanel is a subclass of Container. JFrame, JDialog,
and other are subclasses of Window.) I'm pretty sure you can't put a
Window inside any Container, whereas you can put a Container inside
both Windows and other Containers.


--

Paul Brinkley
ga...@clark.net


James Kanze

unread,
Sep 28, 2000, 3:00:00 AM9/28/00
to
Gamma wrote:

> I don't know what the theoretical limit on panel nesting is, though.

There isn't any theoretical limit. Each component contains a pointer
to its parents, and each container (a type of component) contains a
list of pointers to its children. About the only thing that might
limit nesting is the fact that much of the layoutting and painting
functionality involves recursively calling the function on the
children. So eventually, stack overflow will intervene. I suspect
that all limits of understandability will have been passed long
before, however.

--
James Kanze mailto:ka...@gabi-soft.de
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
Ziegelhüttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627

Martin Lau

unread,
Sep 28, 2000, 3:00:00 AM9/28/00
to

>
> JPanels can certainly nest quite deep. This is in fact a common
> practice used by designers to make complex layouts using just the
> simple ones (Border-, Grid-, Flow-) plus some spit and polish.
>
> I don't know what the theoretical limit on panel nesting is, though.
>

Okay, thanks!

Stuart Moore

unread,
Sep 29, 2000, 3:00:00 AM9/29/00
to

James Kanze <James...@dresdner-bank.de> wrote in message
news:39D33B05...@dresdner-bank.de...

> Gamma wrote:
>
> > I don't know what the theoretical limit on panel nesting is, though.
>
> There isn't any theoretical limit. Each component contains a pointer
> to its parents, and each container (a type of component) contains a
> list of pointers to its children. About the only thing that might
> limit nesting is the fact that much of the layoutting and painting
> functionality involves recursively calling the function on the
> children. So eventually, stack overflow will intervene. I suspect
> that all limits of understandability will have been passed long
> before, however.
>
Assuming lack of memory hadn't got there first. I wonder what'd happen - I might
write something to do this , see what happens and how long it takes for my comp
to keel over.

Stuart

0 new messages