public int yToLine ( int y ) { FontMetrics fm = this . getFontMetrics ( this . getFont ( ) ) ; int height = fm . getHeight ( ) ; Document doc = this . getDocument ( ) ; int length = doc . getLength ( ) ; Element map = doc . getDefaultRootElement ( ) ; int startLine = map . getElementIndex ( 0 ) ; int endline = map . getElementIndex ( length ) ; return Math . max ( 0 , Math . min ( endline - 1 , y / height + startLine ) ) - 1 ; }
Converts a y co - ordinate to a line index .