1

I´m trying find out how to get a graphic of a specified cell of a tableView. My scenerio looks like this:

TableView cells icons

I know i can get a value of a specified cell, which would look something like this:

getCellValue(TableView table, int column, int row) {
   ((TableColumn)table.getColumns().get(column)).getCellObservableValue(row).getValue();   
}

but i did not find out how to get other TableCell attributes, namely graphics, to test, if the cell gets appropriate icon after validation.

Mono
  • 206
  • 1
  • 21
  • 1
    hmm .. it's been a while, you probably solved this already, but actually I don't quite understand the problem: TableViewMatchers has methods to match the textual cell content against strings, you could implement analogous methods to match graphical cell content against whatever node. – kleopatra Feb 20 '19 at 17:13
  • Sounds like a good point, I will definitely try it once i get back into testing javaFx. Thanks. – Mono Jun 10 '19 at 19:42

1 Answers1

0

The straightforward solution is to define ids for your icons and lookup them in your tests.

To bind icon ids with specific col and row you may use a special id format for this: colN_rowN_iconName.

UPDATE:

To find a specific TableCell object by id we may set an id in the upateItem() method:

    return new TableCell<AspectsTableRowData<?>, String>() {
        @Override
        protected void updateItem(final String item, final boolean empty) {
            super.updateItem(item, empty);

            setId("TODO set my id");
        }
    };
Dmytro Maslenko
  • 2,247
  • 9
  • 16
  • This could be the way, but isn't there really any other way? I would like to get specified TableCell object, but i don't know how. Maybe its not possible and the approach is bad.. – Mono Feb 21 '18 at 15:47
  • I updated my post how to get specified `TableCell` object. – Dmytro Maslenko Feb 21 '18 at 15:57
  • Ok, it looks like there is no way to get, lets say, table cell at row 1 column 3, if it has no id? In other words, i can't solve it with no changes in application code? – Mono Feb 22 '18 at 14:21
  • I don't know such way. – Dmytro Maslenko Feb 22 '18 at 16:10
  • have a look at TableViewMatchers: there are internal methods to match textual cell content against strings - copy those for graphical content. The one drawback might be, that it doesn't seem to test against the actual cell, but against a newly created cell, but most of the time that shouldn't make a difference. – kleopatra Feb 20 '19 at 17:16