KeyEvent.VK_DOWN problems

Hello to all!!I am trying to set the focus of the next textfield pressing the key VK_DOWN like this:

if(ae.getID()==KeyEvent.VK_DOWN){

((JTextField)ae.getSource()).setNextFocusableComponent((JTextField)ae.getSource());

}

But nothing happens, what's wrong?!Thanks!!

[381 byte] By [MrSmyllea] at [2007-10-3 9:39:10]
# 1
Hey!!I got it!!I used nextFocus(), but How can I set the focus of the previous textfield pressing the key VK_UP?!
MrSmyllea at 2007-7-15 4:54:58 > top of Java-index,Desktop,Core GUI APIs...
# 2

> if(ae.getID()==KeyEvent.VK_DOWN){

are you sure that's the code you used?

getID() returns the event number = 400,401,402 for keyTyped/Pressed/Released

KeyEvent.VK_DOWN) = 40

are you trying to add up/down arrow keys to the normal tab-navigation?

if so, try this

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

class Testing

{

public void buildGUI()

{

JPanel p = new JPanel(new GridLayout(4,1));

for(int x = 0; x < 4; x++) p.add(new JTextField(5));

JFrame f = new JFrame();

f.getContentPane().add(p);

f.pack();

f.setLocationRelativeTo(null);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Set forwardKeys = new HashSet(f.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));

forwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0));

f.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardKeys);

Set backwardKeys = new HashSet(f.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

backwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0));

f.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,backwardKeys);

f.setVisible(true);

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable(){

public void run(){

new Testing().buildGUI();

}

});

}

}

Michael_Dunna at 2007-7-15 4:54:58 > top of Java-index,Desktop,Core GUI APIs...
# 3
Show de bola!!!The way I wanted!!!Thanks, body!!!You're the one!!!Thanks a lot!!
MrSmyllea at 2007-7-15 4:54:58 > top of Java-index,Desktop,Core GUI APIs...