Search code examples
javajavafxserializationcheckboxserializable

JavaFX 8 CheckBox serialization


I have object like

class Person extends Human implements Serializable{ //just random example
String name;
CheckBox check;

//other functions with checkbox and name
}

and I want to serialize whole CheckBox object. I found out that it´s not possible for Java FX elements but is there any workaround around that if I want to serialize only one Java FX object per instance?

Thanks for answers.


Solution

  • original answer here

    TableColumn<User, CheckBox> userSelected;
    
    userSelected.setCellValueFactory(arg0 -> {
                User user = arg0.getValue();
                CheckBox checkBox = new CheckBox();
                checkBox.selectedProperty().setValue(user.isSelected());
                checkBox.selectedProperty().addListener((ov, old_val, new_val) -> user.setSelected(new_val));
                return new SimpleObjectProperty<>(checkBox);
            });
        tableView.getColumns().addAll(userSelected);