以下代码应该让程序检测何时在某个 JTextField(称为 timeStep)中按下选项卡并在 TextArea 中显示一条消息(称为 textAreaInsructions),但它似乎不起作用。谁能告诉我为什么?
timeStep.setFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
timeStep.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent evt) {
if(evt.getKeyCode() == KeyEvent.VK_TAB){
instruction = "Enter a real number time step";
textAreaInstructions.setText(instruction);
/* If you want to change the focus to the next component */
//nextJComponent.grabFocus();
}
}
});