为了账号安全,请及时绑定邮箱和手机立即绑定

使用setValueAt重新创建互斥复选框

使用setValueAt重新创建互斥复选框

慕后森 2020-02-02 14:46:02
我有一个使用自定义DefaultTableModel的JTable,该JTable在最后一列中显示了一些布尔值(显示为复选框)。当我添加一个MouseListener来获取所单击内容的值时,似乎不再发生对复选框的切换。// As soon as this is used in the component// that is using the JTable, the toggling stopstable.addMouseListener(new MouseAdapter() {              public void mouseClicked(MouseEvent evt) {                  int col = table.getSelectedColumn();                  int row = table.getSelectedRow();                Object o = table.getModel().getValueAt(row, col);我假设该事件正在由侦听器使用。我可以添加什么到MouseListener代码中以恢复切换行为?编辑:糟糕,问题似乎出在我的优先选择上:@Overridepublic void setValueAt(Object aValue, int row, int column) {    // Attempt at mutually exclusive checkboxes    if( column == 2 ){ // Starts at 0. Seek an alternative solution to avoid hardcoding?        // Algorithm: cycle through List to set other Booleans to false        // Uses entities. Is there another way of getting the number of rows from model?        List<MyEntity> myEntities = this.getDatas();        for( int i = 0; i < myEntities.size(); i++ ){            if( i != row ){                // Make sure this calls parent                super.setValueAt( false , i, 2);            }        }    } else {        super.setValueAt(aValue, row, column); // Call parent class    }}  
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 416 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信