Link to home
Start Free TrialLog in
Avatar of djegamsc
djegamsc

asked on

how do i get the Row and coloumn of A JTextPane.

I have to get a line of string from JTextPane.
   ie, when we  clicked the mouse right button in the TextPane, the correspoding  line should be displayed . how can i get it?  I tryied to get the Row, Colomn of the JTextPane. but i could not get the Row and Coloumn.
 can you solve this prob?
Avatar of nesnemis
nesnemis

I'm not quite sure if you can do that, but if you add a mouselistener and selectd your text first you can use getSelectedText();

Else you can check the mouseposition when you rightclick and calculate the rowNo from that
Avatar of Mick Barry
you could try something like:

int caret = pane.getCaretPosition();
Rectangle rect = pane.modelToView(caret);
approximately not accurate

Font font = pane.getFont();
int lineno = evt.getY()/font.getSize();
Avatar of djegamsc

ASKER


 Hello friends,
     Thanks for your reply.
  Actually wht i did to solve this problem is,
     I calculated line no with help of  some calculation of StartPos, EndPos of the line  by using getCarePosition();
 then Using this startPos, endPos  , we can do Select by using TextPane.select(startPos,endPos);


 

ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial