Terai Atsuhiro 2015-03-17 (火) 18:44:01

http://terai.s55.xrea.com/swing/anchorselection/screenshot.png

table.getTableHeader().addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    JTable table = ((JTableHeader)e.getSource()).getTable();
    if(table.isEditing()) {
      table.getCellEditor().stopCellEditing();
    }
    //table.getSelectionModel().clearSelection();
    //table.getSelectionModel().setAnchorSelectionIndex(-1);
    //table.getSelectionModel().setLeadSelectionIndex(-1);
    table.getColumnModel().getSelectionModel().setAnchorSelectionIndex(-1);
    table.getColumnModel().getSelectionModel().setLeadSelectionIndex(-1);
  }
});