tr.width  = fm.stringWidth(text); tr.height = fm.getHeight();
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; }    if (horizontalAlignment == LEADING) { if (c.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT) horizontalAlignment = LEFT; else if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) horizontalAlignment = RIGHT; } else if (horizontalAlignment == TRAILING) { if (c.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT) horizontalAlignment = RIGHT; else if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) horizontalAlignment = LEFT; }      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;
  public static String layoutCompoundLabel(JComponent c,                                            FontMetrics fm,                                           String text,                                           Icon i,                                           int vert_a,                                            int hor_i,                                            int vert_text_pos,                                           int hor_text_pos,                                            Rectangle vr,                                           Rectangle ir,                                            Rectangle tr,                                           int gap)  {    // view rect 'vr' already ok,     // we need to compute ir (icon rect) and tr (text-rect)	    int next_x = vr.x;    int next_y = vr.y;	    ir.height = ir.width = ir.y = ir.x = 0;    if (i != null)      {        ir.x = vr.x;        ir.y = vr.y;        ir.width = i.getIconWidth();        ir.height = i.getIconWidth();        next_x += gap + i.getIconWidth();        next_y += gap + i.getIconHeight();      }	    tr.x = next_x;    tr.y = vr.y; // + (vr.height/2);    tr.width  = fm.stringWidth(text);    tr.height = fm.getHeight(); // +  fm.getAscent()/2;    return text;  }