You could do this with an ActionListener
.
JTextField textField; // this is your text field
textField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
// Place your code to fill the JTable here.
// Maybe something like:
tableModel.setValueAt(textField.getText(), row, column);
}
}
In the above example, make sure to reference textField
, row
, and column
correctly.
EDIT: As MadProgrammer pointed out, a FocusListener
would provide an even broader implementation: whenever the text field loses focus, the code could be run. That would be implemented as follows:
textField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent fe) {
// Place your code to fill the JTable here.
// Maybe something like:
tableModel.setValueAt(textField.getText(), row, column);
}
}