Forums Register Login

JTable actionlistener not working

+Pie Number of slices to send: Send
My tables are not responding when there is any change. Please help


+Pie Number of slices to send: Send
What does your DetailsTableModel look like? The model is responsible for sending the modification events, do you call proper fireTable... methods when the contents of the model changes?

Edit: I'm assuming you've created the DetailsTableModel class, as it is not part of JDK.
+Pie Number of slices to send: Send
This is my DetailsTableModel. Could you tell me where to add the fire.... command as I have tried adding it and it is not working properly.


+Pie Number of slices to send: Send
Your table model does not contain code to change it's contents. Which of the following you want to support?

1) The table model should reflect changes in the underlying structure (the node field). In this case you'll need to be able to watch for changes in the node field itself (perhaps by adding/implementing change listeners on that class) - the model would register a listener in this class call proper fireTable... method from there.

2) The table model should support edits done by the table (your implementation of the isCellEditable method suggests you want to do this). In this case, you need to override the setValueAt method too and propagate the changes to the node instance. You'd probably call fireTableCellUpdated from the setValueAt method in this case.

The Swing JTable tutorial might give you some more insight. It's an excellent resource, I suggest reading it even if you resolve your current issue without it.
+Pie Number of slices to send: Send
I am not still able to get my head around the problem. i already added the tableChanged method and told the model to listen to it. Then why isn't it listening?
+Pie Number of slices to send: Send
Well, your tableChanged method is attached to your model, but the model is not sending the change events. You cannot receive an event which is not being sent.

The AbstractTableModel provides various methods you can use to send the change events (they all begin with fireTable - I've already mentioned them), but it doesn't call them iself. This is because the AbstractTableModel never changes the data it represents (it really even cannot - they are abstracted away), so you're required to implement both the support for changing the data in the model and sending proper change events when it happens.

If the data the model is based on can change independently of the model (the first option in my previous post), the model needs to get to know about these changes first and then to advertise the changes using change events - again, you need to implement both of these two functionalities yourself.

Have you read the JTable tutorial? Was there anything unclear to you?
+Pie Number of slices to send: Send
I have tried what you have told me but it still does not seem to work
+Pie Number of slices to send: Send
If you changed your code, post what you have now. It might help if you describe the mechanism responsible for changes in the data (ie. is it only the editing done by the table, or something different).
+Pie Number of slices to send: Send
How do i get the values of row, col and value?


+Pie Number of slices to send: Send
The setValueAt method is called by the JTable when user finishes editing a value in a cell. Normally you don't call this method. The JTable knows what is the value the user has entered, and what are the coordinates of the cell, and it will call the setValueAt method of the model with proper values of there parameters.

Your implementation has to make sure that the change will be made in the model's data. So you need to obtain the item corresponding to the row and set its value to the value passed to the setValueAt method.

The fireTableCellUpdated call you've included is OK -- and it should cause your tableChanged method to be called when you've finished editing the value in the user interface. However, as your current implementation does not change the model's data, the displayed value won't change either, obviously. Even after you successfully edit a cell, the model still contains the old, unchanged data.
+Pie Number of slices to send: Send
Thank you so much, I got it..
+Pie Number of slices to send: Send
You're welcome!
Where does a nanny get ground to air missles? Protect this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2119 times.
Similar Threads
JTable problem
JTable jumping
jtable combo box value
what am i doing wrong
JTable displaying input data onto console
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:38:53.