0

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).

arkk
  • 1
  • 1
  • 1
  • What language are you using? – Obsidian Age Dec 11 '17 at 03:18
  • Obviously, java. I changed the original code just by using standart button event handling instead lambda expression. And not used PropertyValueFactory<> but PropertyValueFactory,but why not use PropertyValueFactory? Anyway why it doesnt work. – arkk Dec 11 '17 at 10:46
  • Obviuosly in original link there is some misinformation. – arkk Dec 11 '17 at 11:42
  • In original code there is cue that changes needs -- at first -- that one = // - just to delete comment. Indeed to display button you need put in PropertyValueFactory<>("DUMMY")) instead DUMMY some not empty property even you used for another string column - for example "username" that has at least getUsername() getter with username field, if java-fx property is not present. – arkk Dec 11 '17 at 11:59

0 Answers0