getTopLine & setTopLine in jEditorpane?

T

ted holden

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?
 
C

Christian Kaufhold

ted holden said:
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
 
T

ted holden

Christian said:
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.
 
T

ted holden

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top