Sometimes in Java, One Layout Manager Is Not Enough

Most often when developing Java Swing applications, we need to use several layout managers in several nested panels. This is usually not a problem and is considered the normal practice for all UI development in almost all languages known to man. However, most often for each panel in the UI only one layout manager is needed to achieve the desired effect, but there comes a time when you need to use multiple layout managers for the same container depending on the number components in the container.

One such example would be when creating a Centered Grid like layout.  Most often, GridLayout or GridBagLayout may suffice if the number of components are fixed but if the number of components keep changing, the layout may not be as desired. I faced such a similar problem this afternoon, and here is the solution I came up with. Continue reading “Sometimes in Java, One Layout Manager Is Not Enough”