FirmView
FirmView

Reputation: 3150

gettling changed line numbers in jtextarea

I am trying to get all the line numbers from jtextarea. I though of using the document listener's methods,

 public void insertUpdate(DocumentEvent e) {

 }

 public void removeUpdate(DocumentEvent e) {

 }

I am able to get the currently modiefied line number using the above methods, but when it comes to copy paste (multiple lines) i am unable to get the line number, when we paste we get only the intial line number and not the end line number. Any one know how to get the starting as well as the ending line numbers of multiple lines?

Upvotes: 0

Views: 146

Answers (2)

StanislavL
StanislavL

Reputation: 57381

Use javax.swing.text.Utilities getRowStart/getRowEnd, passing the offsets.

Upvotes: 3

Aurelien Ribon
Aurelien Ribon

Reputation: 7634

If you got the starting line number, you can easily compute the ending one by counting the numbers of '\n' chars in your selected text. endingLineNbr = startingLineNbr + newLinesCount

Upvotes: 1

Related Questions