swing - How to scroll to a given position in a document displayed in a JScrollPane -
in application java swing components have jtextpane inside non-editable jscrollpane, , other fields user can enter criteria. if user clicks button or menu item, there search section of document in jtextpane meets given criteria, , if match found section highlighted.
that part solved; can find relevant document segment, know starts , ends (in terms of integer offsets), , highlight it.
but highlighted segment might have scrolled off screen , need scrolled within visible piece of jscrollpane. see there method scrollrecttovisible(rectangle) on jcomponent seems might job, don't see how convert textual document position integer rectangle.
note non-editable jtextpane , don't want move cursor highlighted segment (the user cannot see cursor anyway), want make segment show within visible area of jscrollpane.
well can use modeltoview(...), can return 1 rectangle object, can use case.
here 1 example @camickr regarding same
one more example here
Comments
Post a Comment