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?
> 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
[quoted text clipped - 4 lines]
> 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

Signature
And in short, I was afraid.
ted holden - 25 Apr 2005 21:20 GMT
>> 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
[quoted text clipped - 14 lines]
>
> 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 - 25 Apr 2005 23:03 GMT
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.
>> 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
[quoted text clipped - 14 lines]
>
> Christian