-1

I've tried to use table.getSelectedRows(), table.getSelectedColumns() but I also want to get direction of drag so I think I need to find the last cell that cursor(cursor of table) on it to get direction of dragging but still have no idea, I try to search for this style of function or solution but still not found. does anyone have a good solution for it? thank you very much

this cell that I point

Illustrative table

ManoDestra
  • 6,325
  • 6
  • 26
  • 50
pteerawat
  • 1
  • 1
  • 1
    *"also want to get direction of drag"* Why? See [What is the XY problem?](http://meta.stackexchange.com/q/66377) – Andrew Thompson May 31 '16 at 13:17
  • thank you for your respond, I want to do a gradient from the first cell that I start to drag to finished at the last cell that I stop dragging that's why I think I need to get last cell position. sorry for asking for attempted solution – pteerawat May 31 '16 at 13:36
  • Maybe try one of [these approaches](http://stackoverflow.com/q/7620579/230513). – trashgod May 31 '16 at 15:18
  • You keep describing **what** you want to achieve, not **why**. Explain it to me as you would explain a program feature, like I'm an end user. What does that 'knowing last cell' allow your software to do, that other programs can't? – Andrew Thompson May 31 '16 at 15:35

1 Answers1

2

You need to use the ListSelectionModel to get this information:

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);
camickr
  • 321,443
  • 19
  • 166
  • 288