GeeCON Prague 2014*
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


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Keeping JTextArea Selected Text Selected " Watch "Keeping JTextArea Selected Text Selected " New topic
Author

Keeping JTextArea Selected Text Selected

Eric Foertsch
Greenhorn

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

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


Eric
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...'
 
GeeCON Prague 2014
 
subject: Keeping JTextArea Selected Text Selected