Here is code: Contoller class:
@FXML private TableView<User> table;
@FXML private TableColumn<User,String> view;
method() {..... ` view.setCellValueFactory( new PropertyValueFactory("DUMMY"));
Callback<TableColumn<User, String>, TableCell<User, String>> cellFactory
= new Callback<TableColumn<User, String>, TableCell<User, String>>() {
public TableCell call( TableColumn<User, String> param) {
final TableCell<User, String> cell = new TableCell<User, String>() {
Button btn = new Button("View");
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
User user = getTableView().getItems().get(getIndex());
System.out.println(user.username
+ " " + user.name);
}
});
setGraphic(btn);
setText(null);
}
}
};
return cell;
}
};
view.setCellFactory(cellFactory);
//add observablelist
table.getItems().setAll(datas);
}`
I have borrowed code from here: How to add button in JavaFX table view Indeed I have nothing do view in my View column. Compiler complains that I cannot use parameterless new PropertyValueFactory<>("DUMMY")) in jdk 1.7 Moreover why I cannot use such expression for button column @FXML private TableColumn view? I also should note that I changed original code with lambda (possible just in 1.8).