getTopLine & setTopLine in jEditorpane?

Discussion in 'Java' started by ted holden, Apr 25, 2005.

  1. ted holden

    ted holden Guest

    Hope somebody can help with this one....

    Apparently at least at one time there were getTopLine and setTopLine methods
    for the swing jEditorPane widget which I'd assume let you read or set the
    number of the first visible line in the widget. You'd need something like
    that to have a body of text scroll automatically to follow something else
    which was going on elsewhere in the application.

    Anybody know what happened to those guys or what if anything has replaced
    them?
     
    ted holden, Apr 25, 2005
    #1
    1. Advertising

  2. ted holden <> wrote:

    > Apparently at least at one time there were getTopLine and setTopLine methods
    > for the swing jEditorPane widget which I'd assume let you read or set the
    > number of the first visible line in the widget. You'd need something like
    > that to have a body of text scroll automatically to follow something else
    > which was going on elsewhere in the application.
    >
    > Anybody know what happened to those guys or what if anything has replaced
    > them?


    I've never seen them. JEditorPane does not even have a notion of "line".
    There are some (usually, bad) similar methods in javax.swing.text.Utilities.

    Use a combination of getViewRect, modelToView, viewToModel and scroll-
    RectToVisible.


    Christian
    --
    And in short, I was afraid.
     
    Christian Kaufhold, Apr 25, 2005
    #2
    1. Advertising

  3. ted holden

    ted holden Guest

    Christian Kaufhold wrote:

    > ted holden <> wrote:
    >
    >> Apparently at least at one time there were getTopLine and setTopLine
    >> methods for the swing jEditorPane widget which I'd assume let you read or
    >> set the
    >> number of the first visible line in the widget. You'd need something
    >> like that to have a body of text scroll automatically to follow something
    >> else which was going on elsewhere in the application.
    >>
    >> Anybody know what happened to those guys or what if anything has replaced
    >> them?

    >
    > I've never seen them. JEditorPane does not even have a notion of "line".
    > There are some (usually, bad) similar methods in
    > javax.swing.text.Utilities.
    >
    > Use a combination of getViewRect, modelToView, viewToModel and scroll-
    > RectToVisible.
    >
    >
    > Christian




    Hi, and thanks, that's at least a sort of a starting point.

    Three of those functions are still there; getViewRect doesn't seem to be.

    I've got a distribution of Java from around six months ago on the machine
    I'm using.

    It could be I should be looking for something other than jeditorpane. I
    don't really need full html functionality, being able to highlight small
    text areas in a red font is about all I really need, but I also need to be
    able to scroll programmatically, and to read and set first visible line.
    Ideal would be something like the Borland richtext editor widget.
     
    ted holden, Apr 25, 2005
    #3
  4. ted holden

    ted holden Guest

    Actually.... It's always better to be lucky than good. Sometimes if you
    screw around with something long enough you turn up something which works,
    and this seems to:


    int fontheight;

    Font iif;
    FontMetrics iifm;
    Rectangle iirect = new Rectangle();

    iif = iitextpanel.getFont();
    iifm = getFontMetrics (iif);

    fontheight = iifm.getHeight();

    iirect.height = 0;
    iirect.width = 0;
    iirect.x = 0;
    iirect.y = 0;
    iitextpanel.scrollRectToVisible(iirect);
    //set top line to zero, this step needed if you start off below
    //the line you want to come to.

    iirect.height = iitextpanel.getHeight();
    iirect.width = iitextpanel.getWidth();
    iirect.x = 0;
    iirect.y = 103*fontheight; // 103 = some # of lines for testing
    // i.e. first visible line should be 103
    iitextpanel.scrollRectToVisible(iirect);


    The key to it is using the scrollRectToVisible function, again thanks.




    Christian Kaufhold wrote:

    > ted holden <> wrote:
    >
    >> Apparently at least at one time there were getTopLine and setTopLine
    >> methods for the swing jEditorPane widget which I'd assume let you read or
    >> set the
    >> number of the first visible line in the widget. You'd need something
    >> like that to have a body of text scroll automatically to follow something
    >> else which was going on elsewhere in the application.
    >>
    >> Anybody know what happened to those guys or what if anything has replaced
    >> them?

    >
    > I've never seen them. JEditorPane does not even have a notion of "line".
    > There are some (usually, bad) similar methods in
    > javax.swing.text.Utilities.
    >
    > Use a combination of getViewRect, modelToView, viewToModel and scroll-
    > RectToVisible.
    >
    >
    > Christian
     
    ted holden, Apr 25, 2005
    #4
    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. Thang Nguyen

    Extract JEditorPane from swing jar

    Thang Nguyen, Jul 24, 2003, in forum: Java
    Replies:
    1
    Views:
    378
    Harald Hein
    Jul 24, 2003
  2. Romano Signorelli
    Replies:
    0
    Views:
    699
    Romano Signorelli
    Jul 31, 2003
  3. slc
    Replies:
    0
    Views:
    444
  4. GALZ
    Replies:
    0
    Views:
    845
  5. Mike
    Replies:
    5
    Views:
    5,114
Loading...

Share This Page