Click to See Complete Forum and Search --> : Need help redrawing/sizing JPanels


Splatt
September 14th, 2000, 12:37 PM
Here's the situation:

I have a JPanel (call it mainPane) contained within a JFrame (call it mainFrame). It is added via

mainFrame.getContentPane().add(mainPane);




To mainPane I am adding and removing other JPanels. What I would like to do is that whenever a JPanel contained in mainPane is removed or set invisible the window shrinks to show the deletion, so that the space taken up by the pane is no longer there. Right now whenever a pane is set invisible it still takes up room, and so the window doesn't shrink. I'm left with these big empty spaces.

Any ideas would be most appreciated.

Thanks!


"There's nothing more dangerous than a resourceful idiot." ---Dilbert

Phill
September 15th, 2000, 11:33 PM
Hi there
I think that you arent re setting the size and
then validating.
This is a way you can do it.
Set up two methods, add() and remove() which
both have JPanels for method parameter's, and
then call either one ie:
add(nameOfJPanel);
or
or remove(nameOfJPanel);

The add() method could look like this:
void add(JPanel jp){
getContentPane().add(jp);
setSize(400,400);
validate();
}


and the remove method could look like this :
void remove(JPanel jp){
getContentPane().remove(jp);
setSize(0,0);
validate();
}


Good Luck
Phill.