if (icon == null)
if (horizontalTextPosition == LEADING)
  public static String layoutCompoundLabel(FontMetrics fm,                                           String text,                                           Icon icon,                                           int verticalAlignment,                                           int horizontalAlignment,                                           int verticalTextPosition,                                           int horizontalTextPosition,                                           Rectangle viewR,                                           Rectangle iconR,                                           Rectangle textR,                                           int textIconGap)  {    // Work out basic height and width.    if (icon == null)      {        textIconGap = 0;        iconR.width = 0;        iconR.height = 0;      }    else      {        iconR.width = icon.getIconWidth();        iconR.height = icon.getIconWidth();      }    textR.width = fm.stringWidth(text);    textR.height = fm.getHeight();     // Work out the position of text and icon, assuming the top-left coord    // starts at (0,0). We will fix that up momentarily, after these    // "position" decisions are made and we look at alignment.    switch (horizontalTextPosition)      {      case LEFT:        textR.x = 0;        iconR.x = textR.width + textIconGap;        break;      case RIGHT:        iconR.x = 0;        textR.x = iconR.width + textIconGap;        break;      case CENTER:        int centerLine = Math.max(textR.width, iconR.width) / 2;        textR.x = centerLine - textR.width/2;        iconR.x = centerLine - iconR.width/2;        break;      }    switch (verticalTextPosition)      {      case TOP:        textR.y = 0;        iconR.y = textR.height + textIconGap;        break;      case BOTTOM:        iconR.y = 0;        textR.y = iconR.height + textIconGap;        break;      case CENTER:        int centerLine = Math.max(textR.height, iconR.height) / 2;        textR.y = centerLine - textR.height/2;        iconR.y = centerLine - iconR.height/2;        break;      }    // The two rectangles are laid out correctly now, but only assuming    // that their upper left corner is at (0,0). If we have any alignment other    // than TOP and LEFT, we need to adjust them.    Rectangle u = textR.union(iconR);    int horizontalAdjustment = viewR.x;    int verticalAdjustment = viewR.y;    switch (verticalAlignment)      {      case TOP:        break;      case BOTTOM:        verticalAdjustment += (viewR.height - u.height);        break;      case CENTER:        verticalAdjustment += ((viewR.height/2) - (u.height/2));        break;      }    switch (horizontalAlignment)      {      case LEFT:        break;      case RIGHT:        horizontalAdjustment += (viewR.width - u.width);        break;      case CENTER:        horizontalAdjustment += ((viewR.width/2) - (u.width/2));        break;      }    iconR.x += horizontalAdjustment;    iconR.y += verticalAdjustment;    textR.x += horizontalAdjustment;    textR.y += verticalAdjustment;    return text;  }