File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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...'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Keeping JTextArea Selected Text Selected
 
Similar Threads
How to color a particular sentence in JEditorPane.
simple KeyEvent to move graphic
Listening for keyPressed Event
keycode capturing not working
Disabling up/down arrow key does not disable navigation in rich:extendedDataTable