• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing Cursor in JTextArea

 
Arka Sharma
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find Rob Camick's Protected Text Component useful.
 
Arka Sharma
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic