Set The Character
Hey,
I'm trying to set the caret in a text field. Actually its ann array of text fields like:
inputDisplayNameTextArea2=new JTextArea();
But I want to be able to press the up arrow and have the caret be at the text area above it. I've already implemented a keylistener so it knows when the up button was pressed and it can get the source of which JTextArea produced the area. Now I only need to know how to change the caret from one text area to another. Any help please?
[505 byte] By [
blackmagea] at [2007-11-27 6:46:28]

A more direct approach (no KeyListeners or key bindings) is to use setFocusTraversalKeys:
[url=http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setFocusTraversalKeys(int,%20java.util.Set)]http://java.sun.com/javase/6/docs/api/java/awt/Component.html#setFocusTraversalKeys(int,%20java.util.Set)[/url]
Ok so far I've implemented the key traversals wtih
forwardKeys = getFocusTraversalKeys(
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
backwardKeys= getFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS);
newBackWarsKey=new HashSet(backwardKeys);
newBackWarsKey.add(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));
newForwardKeys = new HashSet(forwardKeys);
newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0));
inputDisplayNameTextArea.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, newForwardKeys);
inputDisplayNameTextArea.setFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, newBackWarsKey);
And the keys go from side to side perfectly. But I can't get them to go up or down. Any suggestions?