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

Posted on 2004-09-21
Last Modified: 2012-05-05
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?
Question by:djegamsc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 12119891
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
LVL 92

Expert Comment

ID: 12120038
you could try something like:

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

Expert Comment

ID: 12124036
approximately not accurate

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

Author Comment

ID: 12168781

 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,endPos);



Accepted Solution

modulo earned 0 total points
ID: 12446004
PAQed, with points refunded (500)

Community Support Moderator

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 160
servlet and mdb, jms error 1 82
Selenium docs api java index 3 97
Eclipse with various Java releases 7 87
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question