tags:

views:

118

answers:

0

I have a JPanel and when its layout changes, I need to re-layout the parent. This can easily be done with panel.getParent().validate(), but the problem is, I don't always know if its direct parent, or maybe some parent somewhere in the tree is really the one that needs to be validated. Is there a way for a parent component to listen to see when its child component is re-layed out so the parent can then relay itself out.

edit: clarification

In my case, the parent has some extra components that need to be relayed out when the child changes, but this isn't always the case. The same child could be use on another parent where the parent doesn't need to be relayed out, so I want to let the parent decide if/when it should relay itself out.

// this layoutChangedListener is what I'm trying to accomplish
child.addLayoutChangedListener(new LayoutChangedListener() {
    public void layoutChanged() {
      parent.validate();
    }
});

thanks,

Jeff