Re: Get the screen position for the caret in JEditorPane

Discussion in 'Java' started by Stefan Istrate, Apr 16, 2009.

  1. On Apr 16, 1:08 pm, TiloVillwock <> wrote:
    > On Apr 16, 12:32 am, Stefan Istrate <> wrote:
    >
    > > I have a JEditorPane in which I am writing text. How can I get the
    > > position on the screen were a character is inserted? I want to use
    > > this position to display there a popup window.

    >
    > > Thanks,
    > > Stefan

    >
    > That's a tricky one. I guess you could try to locate the position by
    > measuring the font size with the FontMetrics class, though this
    > definately not the easiest approach.
    >
    > Tilo


    Meanwhile, I found a solution. Having a JEditorPane called "editor", I
    can get the screen position using:

    Point p = editor.getCaret().getMagicCaretPosition();
    SwingUtilities.convertPointToScreen(p, editor);


    Stefan
     
    Stefan Istrate, Apr 16, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DaveR
    Replies:
    2
    Views:
    6,656
    Dave Rudlin
    Nov 17, 2004
  2. Robin
    Replies:
    0
    Views:
    738
    Robin
    May 12, 2005
  3. Stefan Istrate
    Replies:
    1
    Views:
    346
    TiloVillwock
    Apr 16, 2009
  4. torch
    Replies:
    3
    Views:
    150
    Thomas 'PointedEars' Lahn
    Jun 20, 2004
  5. brendan
    Replies:
    0
    Views:
    213
    brendan
    Aug 29, 2006
Loading...

Share This Page