So I'm trying to add a ChoiceBox for every variable inserted in the TableView.
Users.java:
Users(String userName , Integer userAge , ChoiceBox employed)
{
this.userName = userName ;
this.userAge = userAge ;
this.employed= employed;
}
//getters and setters
Main.java:
ObservableList<Users>userList = FXCollections.observableArrayList();
TableView<Users> userTable = new TableView();
TableColumn<Users, String> nameCol = new TableColumn();
TableColumn<Users, Integer> ageCol = new TableColumn();
TableColumn<Users, ChoiceBox> employCol = new TableColumn();
private ChoiceBox createBox(){
ChoiceBox box = new ChoiceBox();
box.getItems.addAll("true" , "false");
box.setValue("true");
return box;
}
userList.addAll(new User("James" , 47 , createBox()));
Everything compiles and runs just fine, but I have no way of getting a reference to the box
that is clicked by the user. I tried getting it via selection model:
userTable.getSelectionModel().getSelectedItem().employed;
but this just gives me a NullPointerException. I need to be able to select the choice box, if the user selects "true" , then it would display in a text field, but that's an easy fix, I'm having trouble actually getting the instance to the choicebox. I've referred to:
Getting selected item from a JavaFX TableView
javafx: attach ChoiceBox to a TableCell on a TableColumn during Edit
ChoiceBox with custom Item in a TableView
But to no avail. I've also tried using multiple variations of
ChoiceBoxTableCell
and
ChoiceBoxTableList
but these won't even compile, I keep getting a callback error.