Java/Swing: JTable.rowAtPoint doesn't work correctly for points outside the table?
Posted
by Jason S
on Stack Overflow
See other posts from Stack Overflow
or by Jason S
Published on 2010-04-22T15:20:21Z
Indexed on
2010/04/22
15:23 UTC
Read the original article
Hit count: 150
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?
© Stack Overflow or respective owner