I'm looking for a way to view the contents of a file in a JTextArea in such a way that I can scroll back and forth through the file. The catch is that I only want to load a portion of the file (in the case of large files) to improve performance and avoid memory overflow.

When scrolling through the JTextArea (which presumably would be inside of a JScrollPanel), I will need some way to recognize when I've scrolled past, say 50% of, what's in the JTextArea so that I can reload it with the next chunk of the file.

The general idea is to only populate the JTextArea with a set number of characters and to dynamically retrieve chunks of the file as needed.

Any suggestions on how to approach this?