views:

128

answers:

3

I want my panel to fit the frame when I show/hide fields. How could I notify to the parent frame to revalidate?

I thought about pass the frame to my panel's constructor, but I think may have a way this is already done. I remember that there was a protected attribute in JPanel, but there isn't.. maybe i remembering the wrong component.

+1  A: 

you could override the addNotify in the panel into something:

public void addNotify() {
    getParent().revalidate();
    repaint();
    super.addNotify();
}

Not sure if that's what you mean though.

aioobe
+1  A: 
SwingUtilities.getRoot(this).invalidate();
Devon_C_Miller
+1  A: 

I need show/hide some fields of my panel, and I want the panel to fit the frame.

You mean like a summary/details view and you want the frame size to change? Then try:

SwingUtilities.windowForComponent(...).pack();

camickr