Solved

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

Posted on 2004-09-21
6
367 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Message handling in Service Layer 3 58
@SBGen Method 3 38
eclipse package explorer vs project explorer view 2 84
eclipse argument 14 53
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now