I have this code to get a row from a JTable that is generated by a DragEvent for a DropTarget in some component C which may or may not be the JTable:
public int getRowFromDragEvent(DropTargetDragEvent event) {
Point p = event.getLocation();
if (event.getSource() != this.table)
{
SwingUtilities.convertPointToScreen(p,
event.getDropTargetContext().getComponent());
SwingUtilities.convertPointFromScreen(p, this.table);
if (!this.table.contains(p))
{
System.out.println("outside table, would be row
"+this.table.rowAtPoint(p));
}
}
return this.table.rowAtPoint(p);
}
The System.out.println is just a hack right now. What I'm wondering, is why the System.out.println doesn't always print "row -1". When the table is empty it does, but if I drag something onto the table's header row, I get the println with "row 0". This seems like a bug... or am I not understanding how rowAtPoint()
works?