Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Position of a selected JTable cell?

Tags:

java

swing

jtable

I have a JFrame with a few JTables. On one certain JTable, I need the position of the cell in the JFrame that is selected (selection done via code), as soon as it is selected. I would like to draw something here on a Glass Pane. How can I accomplish this?

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

I thought this could get me the upper left hand corner of the table. And via Cell Height and the SelectionListener I could claculate the position i need. But i ca´t even get the uppper left hand corner of the table. Why not? The gui.rerouteTable.getLocation() return (0,0) so obviously the convertPointToScreen is not working correctly.

like image 327
Hans En Avatar asked Oct 22 '13 10:10

Hans En


People also ask

Which of the following model determines how items are selected in JTable?

ListSelectionModel newmodel = mytable.

How can I tell if a row is selected in JTable?

So you can call table. getSelectionModel(). isSelectionEmpty() to find out if any row is selected.

What is table model in java?

The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model. The JTable can be set up to display any data model which implements the TableModel interface with a couple of lines of code: TableModel myData = new MyTableModel(); JTable table = new JTable(myData);


1 Answers

Use JTable's method

public Rectangle getCellRect(int row, int column, boolean includeSpacing)
like image 143
StanislavL Avatar answered Sep 19 '22 02:09

StanislavL