I am trying to write a Swing based application with a main frame containing 2 panels:
- a main top panel (always visible)
- a bottom panel that comes and goes.
When the user clicks on a button named "Show Cache", I want the bottom panel to show up below the main panel. When the user clicks on another button "Hide Cache", I want the new panel to disappear.
Whether the bottom panel is visible or not, I do not want the appearance of the top panel to change.
I have tried many things but I can't get it to work properly:
1st problem: typically, when I click on "Show Cache", the frame does not get larger and the bottom panels fills the space inside the frame, leaving a little room above for the main panel.
2nd problem: Now, if I enlarge the window by dragging down its south border, everything looks fine. However, when I click "HIde Cache", the bottom pane disappears as expected, but the freed space is filled by the top main pane, which becomes much larger than at the beginning. I want the freed space to vanish.
I have tried setVisible(true/false), I have tried setSize on the panel to resize it, I have tried add and remove on the new panel... Nothing works fine. Each time the top pane is affected by the creation of the bottom pane or by its disappearance.
Thanks in advance for your help.
Well, you could try calling pack() on the frame when you show or hide the bottom panel and see if that does what you want.
Otherwise, you have to explicitly set the size of the frame by figuring out how much space you need for each component and when you show or hide the bottom panel, set the frame size accordingly.
Instead of creating multiple posts why don't you try reading your [url http://forum.java.sun.com/thread.jsp?thread=561186&forum=57&message=2759482]original post so people don't waste time answering questions that have already been answered.