Obtaining line & column in JEditorPane

Posted on 2005-04-07
Last Modified: 2012-05-05
I want to write an editor using JEditorPane. I know how to obtain caret position. But I would like to obtain current line & column where the caret is. Is there some simple method to do this, without  keeping and updating "by hand" a table of begins of lines?
Question by:rainette
    LVL 92

    Accepted Solution


    Author Comment

    To objects: thank you, but the article in your link doesn't respond to my problem. I don't want to add line number to every line displayed. Instead I want to track a caret movement and "translate" its position into line/column displayed in "status line".
    To do this I could build a table od lines beginnings and search it everytime when the caret position changes. But  in a case of "true" editing action, i.e. inserting or deleting I have to rebuild that table i.e. to rescan  the whole document. For example I have to do it after every character typing. And my problem is: how could I do this "translation" without superfluous waste of time ?
    LVL 92

    Expert Comment

    There is no simple way that I'm aware of, shouldn't the link I posted above help based on it needs to determine the line number to display it?

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    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:

    755 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

    18 Experts available now in Live!

    Get 1:1 Help Now