Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Starting TextArea from the Top Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Starting TextArea from the Top" Watch "Starting TextArea from the Top" New topic

Starting TextArea from the Top

Mike Cutter
Ranch Hand

Joined: Jun 09, 2002
Posts: 49
I created a TextArea(50,80). I have wrote code to put the contents of a text file into the TextArea. Sometimes, there are over 300 lines in a file and the TextArea will scroll down to the end. Is there a way so after the file has been read, the TextArea will be at the beginning of the file (the first line of the TextArea) instead of the end?

FTPClient ftp = new FTPClient();
BufferedReader buffStream;
String inputLine;
String file;
String login = "root";
String password = "password";

ftp.login(login, password);
buffStream = new BufferedReader(new InputStreamReader(ftp.retrieveFileStream(file)));
while (null != (inputLine = buffStream.readLine())) {
resultFld.append(inputLine + "\n");
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Mike Cutter
Ranch Hand

Joined: Jun 09, 2002
Posts: 49
I never knew about setCaretPosition(0)!

Thanks to your expertise, my applet works like a charm.
I agree. Here's the link:
subject: Starting TextArea from the Top
It's not a secret anymore!