So, i have a situation where, a scrollbar needs to scroll automatically when meets a certain logical situation.
In my case, i have few lines written on JTextPane, and i am highlighting the words.So, when the point is reached,where the text is not visible,the scroll bar should automatically scroll down.
Few screen shots will make it clear:

As you can see, now the screen is filled with the highlited text.So at this point the scrollbar should move down, something like this:

I am blank which logic to use beacuse:
1) The number of lines of .txt file will change.
2)The timing of highlighting of words may change.
Any logic to overcome this situation?
You can simply use the
JTextComponent.modelToView(int)method to find out the location of a given position in the text and then usescrollRectToVisible.Small demo example:
(For the demo purposes, I made the screen quite small and the reader must be furiously good ;-))