Question

I am writing a database program that allows searches for imported books. On the left hand side of my screen is a Spark TextArea and on the right is a List that shows the results of the search.

When I click on the List, I load the chapter into the TextArea. Here is my problem that I simply cannot figure out. I want the top sentence in the TextArea to be the sentence that was clicked in the List.

I know how many sentences are in my TextArea because I control the "\n". How do I get line xx at the top of TextArea?

For instance, the user searches for "truth" and finds 20 entries for this book. He clicks on a choice in List. That chapter is loaded into the TextArea. This particular chapter has 400 lines. The line I want at the top is line 230. The user can immediately see the context for what follows his choice. He may scroll up to see what precedes.

I've searched and tried a host of ideas but with no success.

Can anyone help with this?

Thanks!

Was it helpful?

Solution

Use TextArea#scrollToRange(). You just pass in the index of the first character of the result and it will scroll to the position you want. I've used it in the past and I remember it working, though it can take some work to get it working exactly as you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top