I agree with the accepted answer, except that I would prefer editor.getSession().getScreenLength().
The issue is that if you enable wrap mode, a long line may break into multiple lines. Thus you will not be able to get correct line count with editor.getSession().getDocument().getLength().