aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextarea and JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextarea and JScrollPane" Watch "JTextarea and JScrollPane" New topic
Author

JTextarea and JScrollPane

zack chancery
Ranch Hand

Joined: Aug 19, 2004
Posts: 33
I have a JScrollPane that contains a JTextarea but on display it is defaulted at being scrolled down to the end meaning i have to scroll up to actually read the text. I want it to be displyed at the top naturally with the option to scroll down. not the other way around.
How can I arrange this?
thanks in advance,
z
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Zack -

That's very bizarre. Can you post the code for the JTextArea and JScrollPane constructor, and where you add them to the interface? I don't know if I can help, but I'll give it a whack.

Have you tried setting the caret position to the first character?

Thanks,

Jeff
[ October 21, 2004: Message edited by: Jeff Bosch ]

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
zack chancery
Ranch Hand

Joined: Aug 19, 2004
Posts: 33
Hi Jeff,
actually i am wrong in my question.
what is happening is taht i am populating the textarea by using the append method to display the results of a query. so naturally it will be scrolled down. ill try using your method.
thanks,
z
Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
I have the same problem - probably because I am also populating the text area using the append method. Here is my code:

private void getData(String file){
String log = file;
String line = "";

try{
reader = new FileReader("c:\\STB_Code\\" + log);
in = new BufferedReader(reader);
while( (line = in.readLine()) != null) {
//write the line to the display area
logDisplay.append(line + "\n");
}//while
}//try
//process exceptions from opening the file and reading lines
catch(FileNotFoundException filenotfoundException) {
JOptionPane.showMessageDialog(this, "File Not Found",
"Error", JOptionPane.ERROR_MESSAGE);
}//catch
catch(IOException ioEx) {
JOptionPane.showMessageDialog(this, "Error Reading Line",
"Error", JOptionPane.ERROR_MESSAGE);
ioEx.getMessage();
}

//Close the file
try {
reader.close();
in.close();
}
catch(IOException ioEx) {
JOptionPane.showMessageDialog(this, "Error Closing File",
"Error", JOptionPane.ERROR_MESSAGE);
ioEx.getMessage();
}

}//end getData


Did you solve this problem? If so could you please share?

Thanks,

Mike


Mike<br />SCJP 1.4<br />----------------------------<br />mdcleary@earthlink.net<br />----------------------------<br />There are 10 types of people<br />in the world. Those that <br />understand binary, and those<br />that don't.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Ah, setting it with append will scroll down. You can set the caret position which should scroll it back up.
Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
Thanks - worked like a charm...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextarea and JScrollPane