Solved

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

Posted on 2004-09-21
6
368 Views
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?
0
Comment
Question by:djegamsc
6 Comments
 
LVL 3

Expert Comment

by:nesnemis
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
0
 
LVL 92

Expert Comment

by:objects
ID: 12120038
you could try something like:

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

Expert Comment

by:expertmb
ID: 12124036
approximately not accurate

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

Author Comment

by:djegamsc
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 TextPane.select(startPos,endPos);


 

0
 

Accepted Solution

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

modulo
Community Support Moderator
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 44
servlet filter example 37 63
servlet example 17 32
pagenation logic how it is working in my code 1 30
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

777 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