If you add items to a StretchableLayoutManager, it will stretch the last element beyond its maximum size. I find that in most cases, if all components have reached their maximum size, I would prefer there to be empty space beyond the last element. This can be achieved by commenting out the following:
void StretchableLayoutManager::layOutComponents (Component** const components, int numComponents, int x, int y, int w, int h, const bool vertically, const bool resizeOtherDimension) { setTotalSize (vertically ? h : w); int pos = vertically ? y : x; for (int i = 0; i < numComponents; ++i) { if (const ItemLayoutProperties* const layout = getInfoFor (i)) { if (Component* const c = components[i]) { // if (i == numComponents - 1) // { // // if it's the last item, crop it to exactly fit the available space.. // if (resizeOtherDimension) // { // if (vertically) // c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos)); // else // c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h); // } // else // { // if (vertically) // c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos)); // else // c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight()); // } // } // else { if (resizeOtherDimension) { if (vertically) c->setBounds (x, pos, w, layout->currentSize); else c->setBounds (pos, y, layout->currentSize, h); } else { if (vertically) c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize); else c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight()); } } } pos += layout->currentSize; } } }
It would also be nice to have some control over the space inbetween the components, although I'm aware that this could be achieved with blank components.
Joe.