How to make a JPanel expand to max width in another JPanel

Martin Nielsen picture Martin Nielsen · Jan 10, 2013 · Viewed 46k times · Source

I feel I need to rephrase the question a bit.

Updated question below.

Answer

Reimeus picture Reimeus · Jan 10, 2013

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));