This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design 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

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?


Justin Fox

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

Joined: Oct 14, 2002
Posts: 8898
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.


Justin Fox
Ilja Preuss

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
author & internet detective

Joined: May 26, 2003
Posts: 32508

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

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: set the cursor back to top in a TextArea
It's not a secret anymore!