0
在任何时候按下回车键后,代码波纹管应该将焦点转移到下一个控件,事件会触发,但.transferFocus不会转移焦点,可能会出现什么问题? 谢谢按下回车键后,JSpinner不会转移焦点
//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");
如果微调不在编辑模式下,编辑器不可见,所以它不会收到事件。我猜你也需要在JSpinner对象上做一个Key Binding。 – camickr 2013-03-07 17:09:03
您是否尝试过'requestFocusInWindow()'(请参见[this](http://stackoverflow.com/questions/15223416/focus-on-component-when-a-panel-is-loaded/15223913#15223913)示例)vs 'transferFocus()'? – 2013-03-07 17:26:54
它处于编辑模式下,除了过程“transferFocus()”以外的代码工作,它运行时没有错误,但不会将焦点转移到下一个控件,焦点停留在JSpinner上。 – 2013-03-07 18:22:54