Cześć,
tak w uproszczeniu. Jest sobie controller z TableView gdzie trzymane są obiekty klasy Pacjent. Controller ten chce wykorzystać w innym oknie, gdzie przy wyborze innego pacjenta ma się zmieniać automatycznie tekst Labela. Zrobiłem to w taki sposób jak poniżej, no ale nie działa.
public class PatientView {
private StringProperty name = new SimpleStringProperty();
public StringProperty nameProperty(){
return name;
}
//....//
}
public class PatientTableController {
@FXML
private TableView<PatientFxView> tableView;
@FXML
private TableColumn<PatientFxView, String> nameColumn;
//....//
private PatientModel patientModel;
@FXML
public void initialize(){
patientModel = new PatientModel();
patientModel.initQueryForAll();
setTableItems();
}
private void setTableItems() {
tableView.setItems(patientModel.getPatientFxList());
peselColumn.setCellValueFactory(cellData -> cellData.getValue().peselProperty().asObject());
nameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
surnameColumn.setCellValueFactory(cellData -> cellData.getValue().surnameProperty());
}
@FXML
public PatientFxView getSelectedPatient(){
if(tableView.getSelectionModel().getSelectedItem()==null){
PatientView patientView = new PatientView();
patientView.setName(" ");
return patientView;
}
return tableView.getSelectionModel().getSelectedItem();
}
}
public class NewVisitController {
@FXML
private PatientsTableController patientsTableController;
@FXML
private Label selectedPatientLabel;
@FXML
public void initialize(){
selectedPatientLabel.textProperty().bind(patientsTableController.getSelectedPatient().nameProperty());
}
}