for (int i = 0; i < count; i++)
Rectangle clip = g.getClipBounds(); SwingUtilities.computeIntersection(rect.x, rect.y, rect.width, rect.height, clip); int line0 = (clip.y - rect.y) / height; line0 = Math.max(0, Math.min(line0, count - 1)); int line1 = (clip.y + clip.height - rect.y) / height; line1 = Math.max(0, Math.min(line1, count - 1)); int y = rect.y + metrics.getAscent() + height * line0; for (int i = line0; i <= line1; i++)
  public void paint(Graphics g, Shape s)  {    // Ensure metrics are up-to-date.    updateMetrics();        JTextComponent textComponent = (JTextComponent) getContainer();        selectedColor = textComponent.getSelectedTextColor();    unselectedColor = textComponent.getForeground();    disabledColor = textComponent.getDisabledTextColor();    selectionStart = textComponent.getSelectionStart();    selectionEnd = textComponent.getSelectionEnd();    Rectangle rect = s.getBounds();        // FIXME: Text may be scrolled.    Document document = textComponent.getDocument();    Element root = document.getDefaultRootElement();    int y = rect.y + metrics.getAscent();    int height = metrics.getHeight();        int count = root.getElementCount();    for (int i = 0; i < count; i++)      {	drawLine(i, g, rect.x, y);        y += height;      }  }