Solved

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

Posted on 2004-09-21
6
372 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
[X]
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
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

626 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