public int yToLine(int y){
  FontMetrics fm=painter.getFontMetrics();
  int height=fm.getHeight();
  return Math.max(0,Math.min(getLineCount() - 1,y / height + firstLine));
}

public int yToLine ( int y ) { FontMetrics fm = painter . getFontMetrics ( ) ; int height = fm . getHeight ( ) ; return Math . max ( 0 , Math . min ( getLineCount ( ) - 1 , y / height + firstLine ) ) ; }
converts a y co - ordinate to a line index .
