private void layoutWithSqueeze(Container parent,Dimension realDim,Dimension startPosition,int stretch){
  int numComponents=parent.getComponents().length;
  int[] dim;
  boolean[] violations=new boolean[numComponents];
  int numViolations=0;
  int numVisible=0;
  for (  Component c : parent.getComponents()) {
    if (c.isVisible()) {
      numVisible++;
    }
  }
  int numSqueezable;
  do {
    dim=new int[numComponents];
    numSqueezable=numVisible;
    for (    boolean b : violations) {
      if (b) {
        numSqueezable--;
      }
    }
    int remainingSqueeze=-stretch;
    numViolations=0;
    for (int i=0; i < numComponents; i++) {
      Component c=parent.getComponents()[i];
      if (c.isVisible()) {
        Dimension cPref=getPreferred(c);
        int adjust=0;
        if (remainingSqueeze > 0 && !violations[i]) {
          adjust=Math.max(1,remainingSqueeze / numSqueezable);
          remainingSqueeze-=adjust;
          numSqueezable--;
        }
        dim[i]=d.getPrimary(cPref) - adjust;
        if (dim[i] < d.getPrimary(c.getMinimumSize())) {
          violations[i]=true;
          numViolations++;
        }
      }
 else {
        dim[i]=0;
      }
    }
  }
 while (numViolations != 0);
  for (int i=0; i < numComponents; i++) {
    Component c=parent.getComponents()[i];
    if (c.isVisible()) {
      Dimension cPref=getPreferred(c);
      shrink(cPref,realDim);
      int xAlign=0;
      int yAlign=0;
      EnumSet<?> flags=constraints.get(c);
      if (flags.contains(SLayout.EXPAND_PERPENDICULAR)) {
        d.setSecondary(cPref,d.getSecondary(realDim));
      }
 else {
        xAlign=getXAlignment(c,realDim);
        yAlign=getYAlignment(c,realDim);
      }
      d.setPrimary(cPref,dim[i]);
      c.setBounds(startPosition.width + xAlign,startPosition.height + yAlign,cPref.width,cPref.height);
      shiftByPrimary(startPosition,cPref);
      addToPrimary(startPosition,padding);
    }
  }
}

private void layoutWithSqueeze ( Container parent , Dimension realDim , Dimension startPosition , int stretch ) { int numComponents = parent . getComponents ( ) . length ; int [ ] dim ; boolean [ ] violations = new boolean [ numComponents ] ; int numViolations = 0 ; int numVisible = 0 ; for ( Component c : parent . getComponents ( ) ) { if ( c . isVisible ( ) ) { numVisible ++ ; } } int numSqueezable ; do { dim = new int [ numComponents ] ; numSqueezable = numVisible ; for ( boolean b : violations ) { if ( b ) { numSqueezable -- ; } } int remainingSqueeze = - stretch ; numViolations = 0 ; for ( int i = 0 ; i < numComponents ; i ++ ) { Component c = parent . getComponents ( ) [ i ] ; if ( c . isVisible ( ) ) { Dimension cPref = getPreferred ( c ) ; int adjust = 0 ; if ( remainingSqueeze > 0 && ! violations [ i ] ) { adjust = Math . max ( 1 , remainingSqueeze / numSqueezable ) ; remainingSqueeze -= adjust ; numSqueezable -- ; } dim [ i ] = d . getPrimary ( cPref ) - adjust ; if ( dim [ i ] < d . getPrimary ( c . getMinimumSize ( ) ) ) { violations [ i ] = true ; numViolations ++ ; } } else { dim [ i ] = 0 ; } } } while ( numViolations != 0 ) ; for ( int i = 0 ; i < numComponents ; i ++ ) { Component c = parent . getComponents ( ) [ i ] ; if ( c . isVisible ( ) ) { Dimension cPref = getPreferred ( c ) ; shrink ( cPref , realDim ) ; int xAlign = 0 ; int yAlign = 0 ; EnumSet < ? > flags = constraints . get ( c ) ; if ( flags . contains ( SLayout . EXPAND_PERPENDICULAR ) ) { d . setSecondary ( cPref , d . getSecondary ( realDim ) ) ; } else { xAlign = getXAlignment ( c , realDim ) ; yAlign = getYAlignment ( c , realDim ) ; } d . setPrimary ( cPref , dim [ i ] ) ; c . setBounds ( startPosition . width + xAlign , startPosition . height + yAlign , cPref . width , cPref . height ) ; shiftByPrimary ( startPosition , cPref ) ; addToPrimary ( startPosition , padding ) ; } } }
lay out in sufficient , but smaller space than preferred . respects the minimum dimensions , and squeezes only the components that do not break that constraint .
