CardLayout and different sized panels

Hi,I have two panels in a CardLayout.The problem is those panels have different size, so how can I do they are showed correctly (with the exact size)?Thanks ;)
[187 byte] By [naskara] at [2007-11-26 13:37:22]
# 1

add the smaller one to another panel (holdingPanel),

add the holdingPanel to the cardLayoutPanel

depending where you want the smaller panel to appear in the holdingPanel,

top/bottom/left/right/center/combinationsOf will determine the layout manager

you use for holdingPanel

Michael_Dunna at 2007-7-7 22:24:11 > top of Java-index,Desktop,Core GUI APIs...
# 2

So there is no way to calculate the size automatically? Something like pack...

I tried :

jPanel1.setSize(panel1.getSize());

CardLayout cl = (CardLayout)(jPanel1.getLayout());

cl.show(jPanel1, "1");

(jPanel1 is the CardLayout panel, and panel1 the panel I want to show)

But it does not work...

naskar_a at 2007-7-7 22:24:11 > top of Java-index,Desktop,Core GUI APIs...
# 3

> So there is no way to calculate the size automatically?

LayoutManagers will calculate the size automatically based on the preferred size of the components added to a container.

You can override the preferred size of a component by setting the preferred size of the component.

The CardLayout will use the largest preferred size of all the components added to the card layout.

> But it does not work...

3 lines of code does not show us what you are doing.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-7 22:24:11 > top of Java-index,Desktop,Core GUI APIs...