• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keeping JTextArea Selected Text Selected

 
Eric Foertsch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

jtaInputArea.setCaretPosition(selectionStart);
jtaInputArea.moveCaretPosition(selectionEnd);
jtaInputArea.setFocusable(true);

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

Any ideas?

Thanks

Eric
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic