tags:

views:

36

answers:

2

I've got a custom window class that is a couple levels down extending a JDialog. We have windows that we create and sometimes we create new windows as children of existing windows using the constructor that takes a parent argument.

I need to put some code somewhere in our custom class that does something different depending on whether not the window has children. I know of getParent(), etc, and I can see that I can loop through the components of the window, but for the life of me, I can't seem to figure out how to determine whether or not my current window has any child windows.

Is there a way to do this? Any help is, as always, much appreciated.

+2  A: 

See Window.getOwnedWindows().

Noel Ang
Yeah, I stumbled upon that almost exactly when the two of you answered. That's it, but it doesn't seem to clean up after itself when the children are removed. Guess this won't quite work for me, but it is the answer to my question, so I'll accept.
Morinar
Morinar, Window does not provide an interface for you to disassociate members from its ownership, so I am not sure why you expect that this data needs to be cleaned up. There are two notions of "children" here: Window-as-Container has child components, which are not the same as a Window owning other Windows.
Noel Ang
I take that back: Calling Window.dispose *does* update its ownership relationships, so it is cleaning itself up. If this isn't sufficient for your particular needs, please elaborate.
Noel Ang
It looks like that in our code those child windows still exist in the owned window list of the parent. It could simply be because we are merely hiding them rather than disposing/destroying them. Either way, you definitely gave me the info I was looking for. I'll either figure out how to make this work or try a different solution. Again, thanks for the help.
Morinar
+1  A: 

will getOwnedWindows() do? It belongs to java.awt.Window which in JDialog's parent lineage.

DJ