JavaFX 2: need to access underlying object from inside TableCell in TableView
Domanda
I have a TableView for which the base item is a custom class i.e. TableAdapter. I am creating a ContextMenu in a custom cell factory for TableCells. In the EventHandler for the menu item, I need to access the underlying TableAdapter represented by the specific cell where the menu shows. If I call getItem() or getString() they both seems to return a String representation of the object, however, I need the object itself to access other fields. Thanks,
private final class cCustomTableCell extends TableCell {
private ContextMenu menu = new ContextMenu();
public cCustomTableCell(){
MenuItem menuItem = new MenuItem("Show in tree");
menu.getItems().add(menuItem);
menuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
// THIS IS WHERE I NEED TO ACCESS THE UNDERLYING OBJECT
}
});
setContextMenu(menu);
}
Soluzione
Try to define the generic type. for example:
public class CheckBoxTableCell<S> extends TableCell<S, Boolean> {}
The getItem()
should return Boolean in that case
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow