FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont()); SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null,
fm = g.getFontMetrics(tip.getFont()); SwingUtilities.layoutCompoundLabel(tip, fm, text, null,
  public Dimension getPreferredSize(JComponent c)  {    JToolTip tip = (JToolTip) c;    Rectangle vr = new Rectangle();    Rectangle ir = new Rectangle();    Rectangle tr = new Rectangle();    Insets insets = tip.getInsets();    FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont());    SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), 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);  }