Java 在TableView中的对象arraylist内显示对象arraylist

Java 在TableView中的对象arraylist内显示对象arraylist,java,javafx,tableview,Java,Javafx,Tableview,例如,我想在另一个ArrayList中的ArrayList中显示一个对象 public class Meca { private ArrayList<Ovo> id; int idP=0; Ovo a; Ovo b; public Meca() { id = new ArrayList<Ovo>(); a = new Ovo(10); b = new Ovo(20);

例如,我想在另一个ArrayList中的ArrayList中显示一个对象

public class Meca {

    private ArrayList<Ovo> id;
    int idP=0;

    Ovo a;
    Ovo b;

    public Meca() {
        id = new ArrayList<Ovo>();
        a =  new Ovo(10);

        b = new Ovo(20);
        id.add(a);
        id.add(b);

    }
}

public class Ovo {

    int id;
    public Ovo(int id) {

    this.id = id;
}

public void initialize(URL arg0, ResourceBundle arg1) {

        TableColumn<Meca,Integer> id = new TableColumn("ID Meca");
         id.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getIdP()).asObject());

         TableColumn<Meca,Integer> idOvo = new TableColumn("ID Ovo");

             //HERE IS THE PROBLEM
             idOvo.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getId().get(i).getId()).asObject());




         Meca y = new Meca();

         t.getColumns().addAll(id,idOvo);

        t.getItems().add(y);



}
我可以 在桌子上

public class Meca {

    private ArrayList<Ovo> id;
    int idP=0;

    Ovo a;
    Ovo b;

    public Meca() {
        id = new ArrayList<Ovo>();
        a =  new Ovo(10);

        b = new Ovo(20);
        id.add(a);
        id.add(b);

    }
}

public class Ovo {

    int id;
    public Ovo(int id) {

    this.id = id;
}

public void initialize(URL arg0, ResourceBundle arg1) {

        TableColumn<Meca,Integer> id = new TableColumn("ID Meca");
         id.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getIdP()).asObject());

         TableColumn<Meca,Integer> idOvo = new TableColumn("ID Ovo");

             //HERE IS THE PROBLEM
             idOvo.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getId().get(i).getId()).asObject());




         Meca y = new Meca();

         t.getColumns().addAll(id,idOvo);

        t.getItems().add(y);



}
  • 0 10

  • public class Meca {
    
        private ArrayList<Ovo> id;
        int idP=0;
    
        Ovo a;
        Ovo b;
    
        public Meca() {
            id = new ArrayList<Ovo>();
            a =  new Ovo(10);
    
            b = new Ovo(20);
            id.add(a);
            id.add(b);
    
        }
    }
    
    public class Ovo {
    
        int id;
        public Ovo(int id) {
    
        this.id = id;
    }
    
    public void initialize(URL arg0, ResourceBundle arg1) {
    
            TableColumn<Meca,Integer> id = new TableColumn("ID Meca");
             id.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getIdP()).asObject());
    
             TableColumn<Meca,Integer> idOvo = new TableColumn("ID Ovo");
    
                 //HERE IS THE PROBLEM
                 idOvo.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getId().get(i).getId()).asObject());
    
    
    
    
             Meca y = new Meca();
    
             t.getColumns().addAll(id,idOvo);
    
            t.getItems().add(y);
    
    
    
    }
    
  • 020

  • public class Meca {
    
        private ArrayList<Ovo> id;
        int idP=0;
    
        Ovo a;
        Ovo b;
    
        public Meca() {
            id = new ArrayList<Ovo>();
            a =  new Ovo(10);
    
            b = new Ovo(20);
            id.add(a);
            id.add(b);
    
        }
    }
    
    public class Ovo {
    
        int id;
        public Ovo(int id) {
    
        this.id = id;
    }
    
    public void initialize(URL arg0, ResourceBundle arg1) {
    
            TableColumn<Meca,Integer> id = new TableColumn("ID Meca");
             id.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getIdP()).asObject());
    
             TableColumn<Meca,Integer> idOvo = new TableColumn("ID Ovo");
    
                 //HERE IS THE PROBLEM
                 idOvo.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getId().get(i).getId()).asObject());
    
    
    
    
             Meca y = new Meca();
    
             t.getColumns().addAll(id,idOvo);
    
            t.getItems().add(y);
    
    
    
    }
    
  • 0 30
  • 140
  • 150
我需要显示ArrayList id中的所有对象。我需要为ArrayList中的每个卵形重复相同的MecaId

public class Meca {

    private ArrayList<Ovo> id;
    int idP=0;

    Ovo a;
    Ovo b;

    public Meca() {
        id = new ArrayList<Ovo>();
        a =  new Ovo(10);

        b = new Ovo(20);
        id.add(a);
        id.add(b);

    }
}

public class Ovo {

    int id;
    public Ovo(int id) {

    this.id = id;
}

public void initialize(URL arg0, ResourceBundle arg1) {

        TableColumn<Meca,Integer> id = new TableColumn("ID Meca");
         id.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getIdP()).asObject());

         TableColumn<Meca,Integer> idOvo = new TableColumn("ID Ovo");

             //HERE IS THE PROBLEM
             idOvo.setCellValueFactory(data -> new SimpleIntegerProperty(data.getValue().getId().get(i).getId()).asObject());




         Meca y = new Meca();

         t.getColumns().addAll(id,idOvo);

        t.getItems().add(y);



}
公共类Meca{
私有ArrayList id;
int-idP=0;
卵母细胞;
卵母细胞b;
公共Meca(){
id=新的ArrayList();
a=新卵(10);
b=新Ovo(20);
同上,添加(a);
同上(b);
}
}
公共级Ovo{
int-id;
公共Ovo(内部id){
this.id=id;
}
公共void初始化(URL arg0,ResourceBundle arg1){
TableColumn id=新的TableColumn(“id Meca”);
id.setCellValueFactory(数据->新建SimpleIntegerProperty(data.getValue().getIdP()).asObject());
TableColumn idOvo=新的TableColumn(“ID Ovo”);
//问题就在这里
idOvo.setCellValueFactory(数据->新建SimpleIntegerProperty(数据.getValue().getId().get(i).getId()).asObject());
Meca y=新Meca();
t、 getColumns().addAll(id,idOvo);
t、 getItems()。添加(y);
}