现在,我有一个带有ListSelectionModel和附加的ListSelectionListener的JTable:

ListSelectionModel listSelectionModel = tblCalendar.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());

static class SharedListSelectionHandler implements ListSelectionListener {

    public void valueChanged(ListSelectionEvent e) {

        if (e.getValueIsAdjusting()) {

            //etc.
        }
    }


当我的选择在同一行中更改时,不会调用valueChanged方法。当所选单元格仅在行中更改时,如何调用valueChanged方法?

最佳答案

当所选单元格仅在行中更改时,如何调用valueChanged方法?


您从ListSelectionModelTableColumnModel获得JTable

TableColumnModel tcm = table.getColumnModel();
ListSelectionModel lsm = tcm.getSelectionModel();
lsm.addListSelectionListener(...);

09-05 05:41