Multiple row selection in JTable

后端 未结 4 1804
余生分开走
余生分开走 2020-11-22 07:53

I have a JTable, that has one column that is text which is not editable and the second column is a check box that displays boolean values.... Now what i want is, when the us

4条回答
  •  没有蜡笔的小新
    2020-11-22 08:16

    You can get the selection interval with code similar to this:

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent e) {
            minSelectedRow = ((DefaultListSelectionModel)e.getSource()).getMinSelectionIndex();
            maxSelectedRow = ((DefaultListSelectionModel)e.getSource()).getMaxSelectionIndex();
        }
    });
    

    Then, when one checkbox is checked (listen to ItemEvent) you should iterate from the minSelectedRow to the maxSelectedRow and change checked boxes state. That's it.

提交回复
热议问题