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