private void setSizes(Container parent) {
        int nComps = parent.getComponentCount();
        Dimension d = null;

        // Reset preferred/minimum width and height.
        preferredWidth = 0;
        preferredHeight = 0;
        minWidth = 0;
        minHeight = 0;

        for (int i = 0; i < nComps; i++) {
            Component c = parent.getComponent(i);
            if (c.isVisible()) {
                d = c.getPreferredSize();
                
                int excursionX = c.getX() + (int)Math.max(d.getWidth(), c.getWidth());
                int excursionY = c.getY() + (int)Math.max(d.getHeight(), c.getHeight());
                
                if (excursionX > preferredWidth)
                    preferredWidth = excursionX;
                if (excursionY > preferredHeight)
                    preferredHeight = excursionY;
            }
        }

        minWidth = preferredWidth;
        minHeight = preferredHeight;
        sizeUnknown = false;
    }