• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextarea and JScrollPane

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks - worked like a charm...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic