Can this be done simply, or does one have to go through all the hoops
of getting the viewport, getting the view position, add the event
position
to the view position, get the document, get the text starting at the
position (hmmm - what length to get...), parse it , etc ?
--
Fred
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Actually I am clicking with the right mouse button - I do not wish to
change
the caret position.
--
Fred
from
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html
you can use viewToModel(java.awt.Point)
Thanks, Sigfried.
Here's a solution to getting the text of the line containing
the point clicked in:
int ipos = textarea.viewToModel( e.getPoint );
PlainDocument pd = (PlainDocument)textarea.getDocument();
Element elem = pd.getParagraphElement(ipos);
int ichar1 = elem.getStartOffset();
int ichar2 = elem.getEndOffset();
String line = textarea.getText( ichar1, (ichar2-ichar1+1) );
--
Fred K
String line = textarea.getText( ichar1, (ichar2-ichar1-1) );
--
Fred K