Access JTable cell component

耗尽温柔 提交于 2020-01-06 03:54:08

问题


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.


        }

    }

回答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.



来源:https://stackoverflow.com/questions/36778329/access-jtable-cell-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!