-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
Basically I am trying to find out what column I clicked.
I tried adding a mouse listener to the TableHeader, and use JTable.columnAtPoint() to get the index of the column, but columnAtPoint() does not work seem to work properly with the groups - as far as I can see it returns the lowest grouping correctly, as it appears to be only using the x part of the Point (since it is not an overridden method).
I have added the following which is working:
JBroTable.java
public String getIdentifierAtPoint(Point p) {
int x = p.x;
// Below inherited from {@link JTable#columnAtPoint(p)}
if (!getComponentOrientation().isLeftToRight()) {
x = getWidth() - x - 1;
}
return ((JBroTableColumnModel) getColumnModel()).getIdentifierAtPoint(new Point(x, p.y));
}
JBroTableColumnModel.java
public int getColumnIndexAtY(int y) {
final int MAGIC_HEIGHT_NUMBER = 25;
y += 1; // Results seem off by 1
int correctLevel = 0;
for (int i = 0; i < columns.size() && y > 0; i++) {
y -= MAGIC_HEIGHT_NUMBER;
if (y > 0)
correctLevel++;
}
return correctLevel;
}
public String getIdentifierAtPoint(Point p) {
TableColumnModel delegate = getDelegate(getColumnIndexAtY(p.y));
if (delegate == null)
return null;
return (String) delegate.getColumn(delegate.getColumnIndexAtX(p.x)).getIdentifier();
}
The obvious problem being that MAGIC_HEIGHT_NUMBER is just based off of my own use case. How can we get the row height properly so this returns correctly?