I want to created an editable cell, how should i do that?
Asked
Active
Viewed 48 times
0
-
Personally I'd an an InputListener to the JTable, capture the user's input and modify the TableModel based on that input. Then update the Table with the modified TableModel. Seems like less hassle. – Gorbles Feb 12 '14 at 12:52
-
inputListener? but eclipse does not offer that kind of listener, but ill try to use it. – harraypotter Feb 12 '14 at 12:55
-
My bad, I meant KeyListener. You can build an InputMethodListener from scratch, but that's hell. http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html – Gorbles Feb 12 '14 at 12:57
-
@Gorb i tried to use InputMethodTextChanged but nothing happened – harraypotter Feb 12 '14 at 12:57
-
yeah i tried keylistener too, but didn't work, i guess it really needs a cell editor? but if you have other easier ideas please suggest. Im in great need of help :( – harraypotter Feb 12 '14 at 12:58
-
Looks like you need a `CellEditor`. Look at `DefaultCellEditor` and how to write your own. I'm not sure where to start myself, catching input events in a JTable isn't something I've had to do before. – Gorbles Feb 12 '14 at 13:09
1 Answers
1
As noted in a comment on this related example, a TableCellEditor
serves the JTable
view. Instead, let your model calculate the dependent value when related cells in the same row are changed. You can do this in your implementation of getValueAt()
or setValueAt()
.