Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set caret position to the beginning in JtextArea every time the screen is opened?

 
Rupi Kaur
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a screen with jtextfields, labels and jtextarea. The jtextarea contains comments which occupy multiple lines.
(1) I need that everytime the screen is opened, the comments already present in the jtextarea be visible from the very start, i.e. at caretposition(0).
(2) Also, every time the user leaves the comment field the comments be reset to beginning of the text. I have done this using setcaretposition(0) in focusLost() method.

Please help me implement (1). Attached is the screenshot of how my screen looks like.

Thanks.
jtextArea_Comments.JPG
[Thumbnail for jtextArea_Comments.JPG]
Screenshot of how comments look in multiple lines
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about calling the same method i.e setcaretposition(0), after the form initialization and creation completes.
 
Rupi Kaur
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it , it doesnt work.
 
Rupi Kaur
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I called the method where the model is set and it works now. thanks a lot.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic