B
B
barabash20902019-05-12 17:39:27
Java
barabash2090, 2019-05-12 17:39:27

How to display a collection from a class object?

The essence of the task is that I have a collection of objects of the Person class. And each Person has an ArrayList of objects of the Subject class
5cd82f395d0d2487641195.png
in the left TableView I have a Person list, and in the right TableView I should display the Subject list when clicking on each Person in the left list.
Here is the Controller of this fxml file.

public class SubjectListViewController {
    @FXML
    private TableView<Person> subjectListTable;

    @FXML
    private TableColumn<Person, String> nameColumn;

    @FXML
    private  TableView<Subject> subjectPersonTable;

    @FXML
    private TableColumn<Subject, String> nameSubjectColumn;

    @FXML
    private  TableColumn<Subject, String> courseSubjectColumn;

    private Main main;
    private Stage mainStage;
    Person person;


    @FXML
    private void initialize(){
        nameColumn.setCellValueFactory(
                cellValue -> new SimpleStringProperty(cellValue.getValue().getSurname() + " " + cellValue.getValue().getName().charAt(0) + "."
                        + cellValue.getValue().getFathername().charAt(0) +".")
        );


        subjectListTable.getSelectionModel().selectedItemProperty().addListener(
                ((observable, oldValue, newValue) -> showSubjectListInfo(newValue))
        );

    }

    private void showSubjectListInfo(Person newValue) {


    }


    public void setMain(Main main) {
        this.main = main;
        subjectListTable.setItems(main.personsList);
    }

    public void setMainStage(Stage mainStage) {
        this.mainStage = mainStage;
    }

    public TableView<Person> getSubjectListTable() {
        return subjectListTable;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question