Question

I have a JTable (named InputTable) whose cells are editable. When my program will run, I want the user to input data in the cells of the JTable. After EVERY KEY STROKE, I want to display the following data :

  1. The indices of the row and column of the corresponding cell in which text (data) is being entered
  2. The text (data) in the cell currently being edited

I am using 'Netbeans IDE 7.2 RC1'. I have tried the following but the KeyEvent is not thrown while editing the cell. When I select a cell and start typing, the cell enters in the editing mode and so the key strokes that follow, after the cell enters in the editing mode, don't generate a KeyEvent. And so inputTableKeyTyped() method is not called.

private void inputTableKeyTyped(java.awt.event.KeyEvent evt) {                                    
    // TODO add your handling code here:
    evt.getKeyChar();
    int row_no = inputTable.getSelectedRow();
    int column_no = inputTable.getSelectedColumn();
    String gottenText = (inputTable.getValueAt(row_no, column_no)).toString();
    jLabel1.setText(gottenText);
    jLabel2.setText(Integer.toString(row_no));
    jLabel2.setText(Integer.toString(colummn_no));
    }
}

Thanks in advance

Was it helpful?

Solution

Add a DocumentListener to a custom TableCellEditor, seen here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top