下面的代码应该在任何时候按 Enter 键后将焦点转移到下一个控件,事件触发但 .transferFocus 没有转移焦点,可能有什么问题?谢谢
//JSpinner Creation Code:
private javax.swing.JSpinner edtStockMax;
edtStockMax = new javax.swing.JSpinner();
edtStockMax.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
//Code to bind the Enter key
JSpinnerField1.getActionMap().put("enter-action", new AbstractAction("enter-action")
{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Transfer focus inside JSpinner");
field.transferFocus();
}
});
JSpinnerField1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke("ENTER"), "enter-action");