1

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.


        }

    }
Marquinio
  • 4,601
  • 13
  • 45
  • 68

1 Answers1

1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    I was firing the wrong event when deselecting other list models from my posted method. You were right, it works from stopCellEditing(). I just added this line in my above method and it worked dtm.fireTableCellUpdated(row_,i); Thanks for leading me to the right direction. – Marquinio Apr 22 '16 at 12:49