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
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...
> 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.