I have a JTable with a column that is rendered using a JTextPane-based
cell-renderer.
On a single click on that column in the JTable, I would like to
determine the text offset of the click in the row under the user click.
I thought the code below would work, but the viewToModel() method fails
since the renderer is not actually visible -- internal to the
viewToModel() method, the rectangle that contains the rootView is null,
which causes the method to return -1.
Can't see a workable way of forcing a visible renderer on a mouse click.
Am I missing something or is there an alternate/better way of doing
this?
Thanks,
Gerald
public void mouseReleased(MouseEvent e) {
Point ept = e.getPoint();
int row = table.rowAtPoint(ept);
int col = table.columnAtPoint(ept);
Rectangle r = table.getCellRect(row, col, false);
Point local_offset = new Point(ept.x - r.x, ept.y - r.y);
JTextPaneRenderer jtpr = (JTextPaneRenderer) table.getCellRenderer
(row, col);
int mouseClickOffset = jtpr.viewToModel(local_offset);
}
Christian Kaufhold - 29 Jun 2005 12:50 GMT
> I have a JTable with a column that is rendered using a JTextPane-based
> cell-renderer.
[quoted text clipped - 10 lines]
> Am I missing something or is there an alternate/better way of doing
> this?
Use a TableCellEditor.
Christian
Gerald Rosenberg - 29 Jun 2005 15:17 GMT
> > I have a JTable with a column that is rendered using a JTextPane-based
> > cell-renderer.
[quoted text clipped - 12 lines]
>
> Use a TableCellEditor.
Thanks, but could you explain your suggestion.
Christian Kaufhold - 30 Jun 2005 15:55 GMT
>> > I have a JTable with a column that is rendered using a JTextPane-based
>> > cell-renderer.
[quoted text clipped - 14 lines]
>
> Thanks, but could you explain your suggestion.
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
Christian