I feel I need to rephrase the question a bit.
Updated question below.
The easiest way would be to use another layout manager such as GridLayout
that automatically sizes components to fill the parent container.
myPanel.setLayout(new GridLayout(0, 1));