Get the loacation on screen of a row in a JTable

Hi,

I want the location on screen of a selected row in a JTable.

How can i get this position?

regards

[127 byte] By [Oleka] at [2007-11-27 10:26:43]
# 1

Well to get the row location from a point on the screen you use table.rowAtPoint( someMouseEvent.getPoint() )

But you question seem to require to opposite and I dont know any method for that. You could however, write a function to determine the relative position of the row to the x and y coordinates of the table. Could be tricky though. Unless this is not what you require. Please be a bit more specific

ICE

icewalker2ga at 2007-7-28 17:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 2

I don't really understand the question either.

However, you can use Component.getLocationOnScreen(...) to get the location of the table. Then you need to calculate where the row is. Of course that location can change as the data in the table is scrolled so I'll let you figure out the details.

camickra at 2007-7-28 17:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 3

I mean it like ice thought.

The location of a selected row of a JTable on screen.

Cause - the goal is to open a popup under this row.

The user click on a cell and then the popup should be displayed under this cell.

I have had used a JComboBox but i get some problems with the Event-Handling.

I still used getLocationOnScreen() with the JTable ... then i could multiply the row count with the row height including the cell-space but i thought i can work with something like getRect() or such methods... but ok

thanks anyway

Message was edited by:

Olek

Message was edited by:

Olek

Oleka at 2007-7-28 17:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 4

> The user click on a cell and then the popup should be displayed under this cell.

Then my initial suggestion plus a little tweaking should do the trick.

Copy and complete ...

final JPopupMenu menu = new JPopupMenu();

menu.add("Something");

table.addMouseListener( new MouseAdapter() {

public void mouseReleased(MouseEvent e) {

int row = table.rowAtPoint( e.getPoint() );

int col = table.columnAtPoint( e.getPoint() );

int rowHeight = table.getRowHeight(row);

Rectangle rect = table.getCellRect(row, col, true);

menu.show(table, rect.x, rect.y + rowHeight);

}

});

ICE

icewalker2ga at 2007-7-28 17:41:06 > top of Java-index,Desktop,Core GUI APIs...
# 5

Thats a nice way to achieve the goal.

Thanks ice!

Message was edited by:

Olek

Oleka at 2007-7-28 17:41:06 > top of Java-index,Desktop,Core GUI APIs...