public BufferedImage getImage() {
  if (toolTipObject != -1 && System.currentTimeMillis() > toolTipLastUpdate + TOOL_TIP_DELAY) {
   String[] text = mouseObjects.get(toolTipObject).getToolTipText();
   if (text != null) {
    BufferedImage image = new BufferedImage(finalImage.getWidth(), finalImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = image.createGraphics();
    g.drawImage(finalImage, 0, 0, null); // draw maze

    // Set up for tooltip
    int maxWidth = -1;
    ArrayList<TextLayout> lines = new ArrayList<TextLayout>();
    for (String s : text) {
     AttributedCharacterIterator iterator = new AttributedString(s).getIterator();
     LineBreakMeasurer lbm = new LineBreakMeasurer(iterator, g.getFontRenderContext());
     lbm.setPosition(iterator.getBeginIndex());
     int endPosition = iterator.getEndIndex();

     while (lbm.getPosition() < endPosition) {
      TextLayout layout = lbm.nextLayout(MAX_TEXT_WIDTH);
      lines.add(layout);
      maxWidth = Math.max(maxWidth, (int) (layout.getBounds().getWidth() + 3));
     }
    }

    g.setColor(Color.BLACK);
    FontMetrics m = g.getFontMetrics();
    int outlineWidth = 1;
    int x = mouseX;
    int y = mouseY - m.getHeight() * lines.size();
    int width = maxWidth + 4 + outlineWidth * 2;
    int height = m.getHeight() * lines.size() + 4 + outlineWidth * 2;

    // Make tooltip within the screen
    if (x + width > this.width) x = mouseX - width;
    if (y - height < 0) y = mouseY;
    // Draw black background
    g.fillRect(x, y, width, height);
    g.setColor(Color.WHITE);
    // Draw each line
    for (int i = 0; i < lines.size(); i++)
     lines.get(i).draw(g, x + 2 + outlineWidth, y - m.getDescent() + 2 + outlineWidth - (-i - 1) * m.getHeight());
    // Draw white border
    g.drawRect(x + 1, y + 1, width - 3, height - 3);
    return image;
   }
  }
  return finalImage;
 }