Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I fixed something similar in 2 steps</p> <p>First override the editCellAt from your JTable and call requestFocus after preparing the editor:</p> <pre><code>public boolean editCellAt( int row, int column, EventObject e ) { if ( cellEditor != null &amp;&amp; !cellEditor.stopCellEditing() ) { return false; } if ( row &lt; 0 || row &gt;= getRowCount() || column &lt; 0 || column &gt;= getColumnCount() ) { return false; } if ( !isCellEditable(row, column) ) return false; TableCellEditor editor=getCellEditor(row, column); if ( editor != null &amp;&amp; editor.isCellEditable(e) ) { editorComp=prepareEditor(editor, row, column); if ( editorComp == null ) { removeEditor(); return false; } //aangepast Rectangle rect=getCellRect(row, column, false); if ( datamodel_.useAdaptedEditorRect() ) rect=datamodel_.changeRectangle(rect, editorComp); editorComp.setBounds(rect); add(editorComp); editorComp.validate(); setCellEditor(editor); setEditingRow(row); setEditingColumn(column); editor.addCellEditorListener(this); //NEXT LINE ADDED editorComp.requestFocus(); return true; } return false; } </code></pre> <p>Then overload the requestFocus from your JPanel and make sure your textfield is put as editorComponent:</p> <pre><code>public class EditorPanel extends JPanel { JComponent editorComponent; public boolean isRequestFocusEnabled() { return true; } public void requestFocus() { editorComponent.requestFocus(); } } </code></pre> <p>You can always grab the keyEvent and set it yourself:</p> <pre><code>AWTEvent event = EventQueue.getCurrentEvent(); if ( event instanceof KeyEvent ) { char newSelection = ( (KeyEvent) event).getKeyChar(); int keyCode = ( (KeyEvent) event ).getKeyCode(); editorComponent.requestFocus(); if ( editorComponent instanceof JTextField ) { if ( ( newSelection &gt;= (char) FIRST_ALLOWED_CHAR ) &amp;&amp; ( newSelection != (char) LAST_ALLOWED_CHAR ) ) //comes from DefaultKeyTypedAction ( (JTextField) editorComponent ).setText(Character.toString(newSelection)); if ( keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE ) ( (JTextField) editorComponent ).setText(""); } } else editorComponent.requestFocus(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload