Hello. I want to be able to create a listener for a cell in my JTable. Whenever write a number in a JTable (every key release) I want the value on the other column to decrease something like this:

Quantity|Borrow
  10    |  0
  8     |  2

i use window builder i eclipse. I tried to add a keyrelease action but nothing happened.
Any suggestions?
Thank you.

You need to make JTable with DefaultTableModel and AbstractTableModel and you have methods like:
public void fireTableChanged(TableModelEvent e) - Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
public void fireTableCellUpdated(int row,int column) - Notifies all listeners that the value of the cell at [row, column] has been updated.
Read documentation about DefaultTableModel and AbstractTableModel.

@milil +1 for courage to answer, but be sure is totally wrong, because all those notifiers can firing an Event after TableCellEditor is terminated,

  • job for simple TableCellEditor withr JFormattedTextField linstened by DocumentListener (every key released)

@mKorbel are u saying that@milil 's answer is wrong? sorry, I didn't get it :( I was planning to put a textbox inside a cell and have some keyreleased listener, but ive been trying to put the txtbox in but it wont just work. Is that the right idea? or are there any other else? Thank you.

for TableCellEditor there should be used JFormattedTextField (Whenever write a number in a JTable) as editors component, and this JFormattedTextField listened by DocumentListener (Whenever write a number in a JTable)

Edited 2 Years Ago by mKorbel

can u give me some examples how to do that? Im sorry, but I already searched the net, but can't find the answer i am looking for.

This article has been dead for over six months. Start a new discussion instead.