File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Keeping JTextArea Selected Text Selected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Keeping JTextArea Selected Text Selected " Watch "Keeping JTextArea Selected Text Selected " New topic

Keeping JTextArea Selected Text Selected

Eric Foertsch

Joined: Aug 22, 2004
Posts: 2
Hi All

I have a JTextArea were I am trying to implement a block shift left/right on selected text. I have a KeyListener on the JTextArea where I check for the left or right arrow key. I process the left/right event ok, move my text, but then the text becomes unselected. I have added code to reselect it before I exit and also to make sure the text area still has focus but no luck. I did notice that after a left/right arrow I also get a KeyEvent.VK_ALT event. I am not sure why I am getting that but added code to reselect the text for this key event also. A code snippet of 'reselecting' the text is below


I have checked the selectionStart and selectionEnd values to make sure they are >=0 and <= string lengtht.

Any ideas?



Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try posting a compilable program - nothing fancy, just a frame/textArea and the block shift code,
along with explanation 'if you do this, it should do that, but instead...'
I agree. Here's the link:
subject: Keeping JTextArea Selected Text Selected
It's not a secret anymore!