Reputation: 4831
Ok I have a JTable where I'm displaying a JList on every cell. To do this I had to implement TableCellRenderer and extend DefaultCellEditor. Here is where I return the actual JList to be rendered in GUI.
What I want to do is when user de-selects an item from a JList, I want to also de-select all items for all JLists for that table row starting at the clicked column.
My problem is that I can't figure out a way to de-select all items that come after the current clicked table column. All I can access is this DefaultListModel. I guess I need to access the actual JList in order to remove all selected items.
Below is method I'm using. Any ideas how to do this? Thanks.
public void deselectFromLocation(int row_, int column_){
DefaultTableModel dtm = (DefaultTableModel) table1.getModel();
int cols = dtm.getColumnCount();
for(int i=column_; i<cols;i++){
PCSListModel lm = (PCSListModel) dtm.getValueAt(row_, i);
//How can I access the actual JList object in order to remove all selected items?
//The PCSListMode is DefaultListModel and has no access to JList object. Thanks.
}
}
Upvotes: 1
Views: 439
Reputation: 205885
Presumably, your renderer and editor obtain the existing selection state from your TableModel
, perhaps updating an instance of ListSelectionModel
that is used as part of preparing the component for use. You can update the other model value(s) in your implementation of stopCellEditing()
. Your TableModel
will have to fire a suitable TableModelEvent
for the other cells; do not do so for the value being edited. A related example is seen here.
Upvotes: 1