*
The moose likes Swing / AWT / SWT and the fly likes set the cursor back to top in a TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "set the cursor back to top in a TextArea" Watch "set the cursor back to top in a TextArea" New topic
Author

set the cursor back to top in a TextArea

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
how do i get my cursor back to the top of the JTextArea after i hit enter to send the text over the connection.

it returns to the next line after i hit enter, then i try and set the caret position = to 0, but that only affect that line. how do i make it to where even though im hitting enter, right after that, it clears the text and makes the cursor go back to the first line?

Thanks,

Justin Fox


You down with OOP? Yeah you know me!
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8805
    
    5
let's swing this over to the intermediate forum...


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
I'm using Robot right now, and using it to press backspace right after i hit the enter key, to get it back to the initial position.

Is there a better way?

This seems to be working just fine, but i could've swore I used a different way before.

Thanks,

Justin Fox
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Have you tried setText("")?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Since this question is about Swing and we have a Swing forum, I'm going to move this thread to it.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set the cursor back to top in a TextArea
 
Similar Threads
reset caret position to begining of Jtextpane
Setting cursor position in a text file Java
Set the cursor
First line blank in JTextPane
Text Generation Method