Javafx tableview with data from multiple classes

后端 未结 2 1440
迷失自我
迷失自我 2020-12-20 06:45

I have no problem filling my tableview with diffrent data from 1 class. But it does not work for me with multiple classes. Any idea how to solve that? I have checked out sim

相关标签:
2条回答
  • 2020-12-20 07:06

    In my opition you only have one nice solution for this.

    You need a extra Class that holds your TaskControl, ContextControl and ProjectControl.

    Your Code can look something like that.

    class Wrapper{
     private TaskControl taskControl;
     private ContextControl contextControl;
     private ProjectControl projectControl;
     ...
     public Boolean isDone(){
       return taskControl != null ? taskControl.isDone() : null;
      }
    }
    
    
    @FXML
    private TableView<Wrapper> tblView;
    
    @FXML
    private TableColumn<Wrapper, Boolean> colErledigt;
    
    colErledigt.setCellValueFactory(
                new PropertyValueFactory<Wrapper, Boolean>("isDone"));
    
    0 讨论(0)
  • 2020-12-20 07:09

    Solved it by adding an additional String to my TaskControl, that contains the names of all the projects it contains. It gets the names through a function that I call just before I create the ObservableList for the Table Column.

    private String projectsAsString;
        ...
    public final void convertProjectsToString() {
    
        String projects = "";
    
        for (Project p : this.getProjects()) {
            ProjectControl pp = (ProjectControl) p;
            projects += pp.getName() + ", ";
        }
        if (projects != null && projects != "" && projects.length() > 4) {
            projects = projects.substring(0, projects.length() - 2);
        }
        this.projectsAsString = projects;
    }
    

    Thank you guys anyways for helping me.

    0 讨论(0)
提交回复
热议问题