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]
# 1
textAreaB.requestFocusInWindow() will set the focus to that textarea.
Nethera at 2007-7-12 18:19:01 > top of Java-index,Java Essentials,Java Programming...
# 2
You might want to use a Key Binding instead of KeyListeners. http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
TuringPesta at 2007-7-12 18:19:01 > top of Java-index,Java Essentials,Java Programming...
# 3

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]

Hippolytea at 2007-7-12 18:19:01 > top of Java-index,Java Essentials,Java Programming...
# 4

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?

blackmagea at 2007-7-12 18:19:01 > top of Java-index,Java Essentials,Java Programming...
# 5
So you have a *grid* of text areas?
Hippolytea at 2007-7-12 18:19:01 > top of Java-index,Java Essentials,Java Programming...