代码之家  ›  专栏  ›  技术社区  ›  pteerawat

如何在jtable的区间选择中获取最后选中的单元格

  •  -1
  • pteerawat  · 技术社区  · 9 年前

    我试过用桌子。getSelectedRows(),表。getSelectedColumns(),但我还想获得拖动方向,所以我认为需要找到光标(表的光标)所在的最后一个单元格,以获得拖动方向但仍然不知道,我尝试搜索这种类型的函数或解决方案,但仍然找不到。有人有好的解决方案吗?非常感谢你

    我指的这个牢房

    Illustrative table

    1 回复  |  直到 9 年前
        1
  •  2
  •   camickr    9 年前

    您需要使用ListSelectionModel来获取此信息:

    ListSelectionModel lsm = table.getSelectionModel();
    int start = lsm.getAnchorSelectionIndex();
    int end = lsm.getLeadSelectionIndex();
    System.out.println(start + " : " + end);
    TableColumnModel tcm = table.getColumnModel();
    lsm = tcm.getSelectionModel();
    start = lsm.getAnchorSelectionIndex();
    end = lsm.getLeadSelectionIndex();
    System.out.println(start + " : " + end);