Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextarea and JScrollPane

 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, setting it with append will scroll down. You can set the caret position which should scroll it back up.
 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - worked like a charm...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic