日期:2014-05-20 浏览次数:21243 次
/**
     * Causes this Window to be sized to fit the preferred size
     * and layouts of its subcomponents.  If the window and/or its owner
     * are not yet displayable, both are made displayable before
     * calculating the preferred size.  The Window will be validated
     * after the preferredSize is calculated.
     * @see Component#isDisplayable
     */
    public void pack() {
    Container parent = this.parent;
    if (parent != null && parent.getPeer() == null) {
        parent.addNotify();
    }
    if (peer == null) {
        addNotify();
    }
        Dimension newSize = getPreferredSize();
        if (peer != null) {
            setClientSize(newSize.width, newSize.height);
        }
        if(beforeFirstShow) {
            isPacked = true;
        }
    validate();
    }