Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 9th, 2012  |  syntax: Java  |  size: 0.61 KB  |  views: 101  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //editor is jtextarea
  2.  
  3. Rectangle r = editor.getVisibleRect();
  4. Point top = new Point(r.x, r.y);
  5. Point bottom = new Point(r.x, r.y + r.height);
  6. int startRow = editor.viewToModel(top); // this is working. it shows 0 at initial, then after the line reaches the end and when the scrollbar gets displayed, it shows the numbers correctly, 1,2,3...
  7. int endRow = editor.viewToModel(bottom); // this is not working, when we type, it is taking column numbers
  8. editorLineNo.setText(" START ROW " + startRow + " END ROW" + endRow);
  9.  
  10. What is needed is, start row number and end row number from the jtextarea