aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Changing Cursor in JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Changing Cursor in JTextArea" Watch "Changing Cursor in JTextArea" New topic
Author

Changing Cursor in JTextArea

Arka Sharma
Ranch Hand

Joined: Jun 15, 2011
Posts: 103

Hi,

I want to create a putty like terminal in swing.Now two things are there I'm stuck right now.One the cursor is there I want to make it like ubuntu terminal cursor.A rectangle one.I have found that I need to override damage and paint for that.But I couldn't get much from there.Second is I added a JTextArea in a JFrame which is having the string "[root@localhost]#" but by pressing backspace it is being deleted what I don't want.Please tell me how to acheive these two things.

Regards,
Arka
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Second is I added a JTextArea in a JFrame which is having the string "[root@localhost]#" but by pressing backspace it is being deleted what I don't want.

if the [root@localhost]# is to be on a line of its own i.e. first keystrokes are underneath,
put [root@localhost]# in the top border
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

You might find Rob Camick's Protected Text Component useful.


luck, db
There are no new questions, but there may be new answers.
Arka Sharma
Ranch Hand

Joined: Jun 15, 2011
Posts: 103
if the [root@localhost]# is to be on a line of its own i.e. first keystrokes are underneath,
put [root@localhost]# in the top border



Thanks for your help.And sorry I didn't get you.Will you please explain ?
Arka Sharma
Ranch Hand

Joined: Jun 15, 2011
Posts: 103

I forgot to mension one more thing.In a command prompt when we press enter without typing anything in the command line the prompt appears on the next line.How can I implement it ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

You will need to change the key bindings of your text component to make enter "execute" the part after the current prompt. When this "execution" is done you print the prompt on a new line. When the part is empty the execution is simply to do nothing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Will you please explain ?

the string '[root@localhost]#' becomes part of the border, not the textArea.

the description of the component in Darryl's link does seem to be what you're after.
Arka Sharma
Ranch Hand

Joined: Jun 15, 2011
Posts: 103

Hi,

Protecting the part "[root@localhost ~]" is done.Now I am unable to navigate and delete the text.I have used Darryl's "ProtectedDocument" class.Thanks Darryl for that.Now again I have two requirements.When I am running my swing application the cursor is at line 1 at r.I have passed -1,10 as "protect's" "start" and "end" parameters respectively.Now I want when I start my app and the frame is drawn the cursor should be at the end of "[root@localhost ~]" that is after ']' character.Second thing is I want to implement a key listener which will listen to 'Enter' key and again redraw "[root@localhost ~]" on the next line.But if some command is passed that will be executed and output will be displayed after that "[root@localhost ~]" will be drawn.

Regards,
Arka
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing Cursor in JTextArea
 
Similar Threads
Real Time program updating to screen?
How to reassign STDIN to a JTextArea??
clrscr() in JAVA ???
JTextArea & Cursor
Make line break (go to new line) while writing text on JPanel