I have this code to get a string from a JTable that is created by a DragEvent for a DropTarget in some C component, which may or may not be 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);
}
System.out.println is just a hack right now. I am wondering why System.out.println does not always print "line -1". When the table is empty, it does, but if I drag something into the title bar of the table, I get println with "row 0". This seems like a mistake ... or do I not understand how it works rowAtPoint()?
source
share