given a tableview object I have got the tableposition for the cell I wanted to get. I also got the row and column number of the cell I wanted to get. Let's say it is row 3, column 2, how do I get the cell in row 3 column 2? I want the cell obj itself, not the value of the cell.
Asked
Active
Viewed 491 times
-2
-
you don't want to access the cell :) Why would you? Re-think your goal in terms of a (maybe meta-) model instead of cell. Please also see [my comment](https://stackoverflow.com/questions/52630608/accessing-a-tablerows-style-data-in-a-tableview) – kleopatra Oct 04 '18 at 09:48
-
I needed to color all the cells that have the specific value. That is why i wanted to get access to the cell. Otherwise how could i do it – JiangLone He Oct 04 '18 at 22:04
-
it's the data that drive the view - so you need a custom cell factory which configures itself based on the value – kleopatra Oct 05 '18 at 07:35
1 Answers
-1
If you are using JavaFX 8u40 or above you can get it by using the AccessibleAttribute.
TableCell cell = (TableCell) tableView.queryAccessibleAttribute(AccessibleAttribute.CELL_AT_ROW_COLUMN,rowIndex,columnIndex);
Remember you may get null value if the cell is not visible in the tableView viewport.

Sai Dandem
- 8,229
- 11
- 26
-
no, same comment as in your other answer: there is no way - and for good reason - to reliably access an arbitrary cell – kleopatra Oct 04 '18 at 09:45
-
-
You need to remember that the internal implementation (VirtualFlow) renders the table cells only which needs to be shown in viewport and it reuses the same cells effectively for the rows/columns that need to be shown. So say among 100 rows in table, if viewport shows only the first 10 rows,. obviously there is no need for JavaFX to render the 100th row unless user scrolls to that row. The tweak that I mentioned is a very quick way to get the cell reference in the visible viewport. You need to stick to @kleopatra's comment to rethink, if it is something you need in broader perspective. – Sai Dandem Oct 04 '18 at 23:08