alen_ycc
asked on
how to delete rows in the "view" of JTable?
according MVC(Model-View-Controller) design, i think there should have a method to deal with the row deletion of the JTable's view, but not delete in JTable's Model...
ASKER
ok, then how exactly can delete the rows in runtime?
If you delete a row in a Table but not in the underlying model then you are NOT deleting the row but "hiding" it in in that particular view. That function would therefore be the resposibility of the view, not the model.
The easiest way to do this is to build some row filtering class that sits between the view (JTable) and the model (DefaultTableModel). It adds itself to the TableModel as a listener and allows the JTable to add itself to it as a listener. It then proxies the conversation between the two.
You should be able to find a way of masking off or not displaying certain rows in the Table.
The easiest way to do this is to build some row filtering class that sits between the view (JTable) and the model (DefaultTableModel). It adds itself to the TableModel as a listener and allows the JTable to add itself to it as a listener. It then proxies the conversation between the two.
You should be able to find a way of masking off or not displaying certain rows in the Table.
"If you delete a row in a Table but not in the underlying model then you are NOT deleting the row but
"hiding" it in in that particular view. That function would therefore be the resposibility of the view,
not the model." - The VIEW according to MVC pattern, is responsable for displaying the data from the MODEL, and only for this. Also, the VIE is in direct relation with the CONTROLLER, which listen for any kind of input events. So "hiding" data on the view is a result of implementing a hiding algorithm into the MODEL. This is not a sollution to avoid delete of data contained by the table unless the programmer want's this kind of behaviour.
alen_ycc : I will write shortly to you a example of doing that.
"hiding" it in in that particular view. That function would therefore be the resposibility of the view,
not the model." - The VIEW according to MVC pattern, is responsable for displaying the data from the MODEL, and only for this. Also, the VIE is in direct relation with the CONTROLLER, which listen for any kind of input events. So "hiding" data on the view is a result of implementing a hiding algorithm into the MODEL. This is not a sollution to avoid delete of data contained by the table unless the programmer want's this kind of behaviour.
alen_ycc : I will write shortly to you a example of doing that.
"If you delete a row in a Table but not in the underlying model then you are NOT deleting the row but "hiding" it in in that particular view. That function would therefore be the resposibility of the view, not the model." - The VIEW according to MVC pattern, is responsable for displaying the data from the MODEL, and only for this. Also, the VIEW is in direct relation with the CONTROLLER, which listen for any kind of input events. So "hidding" data on the view is a result of implementing a hidding algorithm into the MODEL. This is not a sollution to avoid delete of data contained by the table unless the programmer want's this kind of behaviour.
alen_ycc : I will write shortly to you a example of doing that.
alen_ycc : I will write shortly to you a example of doing that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ovi, your code is excellent, thanks!
may i have your ICQ No.? my no. is 81119581,
best regards,
alen_ycc
may i have your ICQ No.? my no. is 81119581,
best regards,
alen_ycc
Keep in mind that you have (according to MVC pattern) one single model and virtualy a infinity of views associated to that model.