Get position of selected JTable cell?

I have a JFrame with several JTables. On one specific JTable, I need the position of the cell in the JFrame that is selected (selection is done through code) as soon as it is selected. I would like to do something here on glass glass. How can i do this?

Point p = gui.rerouteTable.getLocation();
SwingUtilities.convertPointToScreen(p,gui.rerouteTable);

I thought this could lead me to the upper left corner of the table. And through Cell Height and SelectionListener I could recoup the position I need. But I canโ€™t even take the upper left corner of the table. Why not? The result of gui.rerouteTable.getLocation () returns (0,0), so it is obvious that convertPointToScreen is not working correctly.

+4
source share
3 answers

Use JTable Method

public Rectangle getCellRect(int row, int column, boolean includeSpacing)
+10

, , isSelected .

: , a TableCellRenderer , value Object, .

+1

Using this code, you can get the x and y coordinates of a cell in a table:

private void jtTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
    int x = jtTable.getSelectedRow();
    int y = jtTable.getSelectedColumn();
} 
0
source

All Articles