public void keyPressed ( KeyEvent evt ) { if ( evt . getKeyCode ( ) == KeyEvent . VK_ENTER ) { boolean bDoTab = true ; int iTextLength = m_control . getDocument ( ) . getLength ( ) ; if ( ( ( m_control . getSelectionStart ( ) == 0 ) || ( m_control . getSelectionStart ( ) == iTextLength ) ) && ( ( m_control . getSelectionEnd ( ) == 0 ) || ( m_control . getSelectionEnd ( ) == iTextLength ) ) ) bDoTab = true ; else bDoTab = false ; // Not fully selected, definitely process this key if ( bDoTab ) { if ( m_bDirty ) bDoTab = false ; // Data changed, definetly process this key } if ( evt . getKeyCode ( ) == KeyEvent . VK_ENTER ) if ( ! bDoTab ) return ; // Do not consume... process the return in the control evt . consume ( ) ; // Don't process the tab as an input character... tab to the next/prev field. this . transferFocus ( ) ; // Move focus to next component return ; } m_bDirty = true ; }
key released if tab select next field .