如题,我分别在两个Panel中创建了两个表格jt1和 jt2遇到的困难是
      点击选择jt1中的某一行   再选择jt2中的某一行发现jt1中的那一行还是处于选择状态
怎样编写使得点击后只能选中两个表格中的某一行而不是两行???
先谢谢各位了!!

解决方案 »

  1.   

    jtable.getSelectionModel().addListSelectionListener(ListSelectionListener x) 然后在自定义的 ListSelectionListener 里清除另一个 jtable 的 selection 
      

  2.   


    比如你有两个 JTable, 名为 table1 和 table2
        table1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {      @Override
          public void valueChanged(ListSelectionEvent e) {
            
            if( e.getValueIsAdjusting() )
              return;
            
            if( !table1.getSelectionModel().isSelectionEmpty() )
              table2.getSelectionModel().clearSelection();
          }
        });