FontMetrics fm; Toolkit g = tip.getToolkit(); text = tip.getTipText();  Rectangle vr = new Rectangle(); Rectangle ir = new Rectangle(); Rectangle tr = new Rectangle(); Insets insets = tip.getInsets(); fm = g.getFontMetrics(tip.getFont()); SwingUtilities.layoutCompoundLabel(tip, fm, text, null, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, vr, ir, tr, 0); return new Dimension(insets.left + tr.width + insets.right, insets.top + tr.height + insets.bottom);
String str = tip.getTipText(); FontMetrics fm = c.getFontMetrics(c.getFont()); Insets i = c.getInsets(); Dimension d = new Dimension(i.left + i.right, i.top + i.bottom); if (str != null && ! str.equals("")) { View view = (View) c.getClientProperty(BasicHTML.propertyKey); if (view != null) { d.width += (int) view.getPreferredSpan(View.X_AXIS); d.height += (int) view.getPreferredSpan(View.Y_AXIS); } else { d.width += fm.stringWidth(str) + 6; d.height += fm.getHeight(); } } return d;
  public Dimension getPreferredSize(JComponent c)  {    JToolTip tip = (JToolTip) c;    FontMetrics fm;    Toolkit g = tip.getToolkit();    text = tip.getTipText();        Rectangle vr = new Rectangle();    Rectangle ir = new Rectangle();    Rectangle tr = new Rectangle();    Insets insets = tip.getInsets();    fm = g.getFontMetrics(tip.getFont());    SwingUtilities.layoutCompoundLabel(tip, fm, text, null,                                       SwingConstants.CENTER,                                       SwingConstants.CENTER,                                       SwingConstants.CENTER,                                       SwingConstants.CENTER, vr, ir, tr, 0);    return new Dimension(insets.left + tr.width + insets.right,                         insets.top + tr.height + insets.bottom);  }