I wrote an application which automatically was putting some pieces of text inside an NSTextView. The problem was that I needed a function to scroll the NSTextView to the bottom if something new is about to be appended.
First we need to definy an NSRange which will be the range of the text inside the NSTextView. After that, it is possible to scroll down. Here is some sample code. Nate that these are just pieces of a whole code - so this wont work as an application right away!
First:
import com.apple.cocoa.foundation.NSRange.*;
//Import this at the top!
public NSTextView mytextfield;
//We also need to definy the NSTextView "mytextfield", which will be used below
We are ready to scroll now:
NSRange myrange = new NSRange(mytextfield.string().length(),0);
//Here, we are getting the content of the NSTextView "mytextfield" inside a String and then get it's length!
this.mytextfield.scrollRangeToVisible(range);
//This is the final scroll function that scrolls our NSRange
This solution is working with Cocoa and JAVA!