Java 如何处理具有嵌套标题的表视图中的信息?

Java 如何处理具有嵌套标题的表视图中的信息?,java,javafx-8,scenebuilder,Java,Javafx 8,Scenebuilder,我想在具有嵌套标题的表视图中设置信息,就像Excel表一样。但是我花了好几个小时没有得到任何可以帮助我的东西 我需要的结果如下: 但是现在看起来是这样的: 设置表中信息的我的代码: JourSuivi j1=new JourSuivi(1, "30/04/2016", 23, 34, new ArrayList<>(), 43, new ArrayList<>(), 345, 23, 2, new ArrayList<>(), 11); JourSuivi

我想在具有嵌套标题的表视图中设置信息,就像Excel表一样。但是我花了好几个小时没有得到任何可以帮助我的东西

我需要的结果如下:

但是现在看起来是这样的:

设置表中信息的我的代码:

JourSuivi j1=new JourSuivi(1, "30/04/2016", 23, 34, new ArrayList<>(), 43, new ArrayList<>(), 345, 23, 2, new ArrayList<>(), 11);
JourSuivi j2=new JourSuivi(1, "30/04/2016", 23, 34, new ArrayList<>(), 43, new ArrayList<>(), 345, 23, 2, new ArrayList<>(), 11);
List<Tonnage>ls=new ArrayList<>();
ls.add(new Tonnage(ls_ton,"ONCF",33));

j1.setNbWgs(ls);j2.setNbWgs(ls);
List<Double> ls_d=new ArrayList<>();
ls_d.add(12.33);ls_d.add(44.2);

j2.setTocpSA(ls_d);j1.setToncf(ls_d);j1.setToncf(ls_d);j2.setToncf(ls_d);
ObservableList<JourSuivi> data=FXCollections.observableArrayList(j1,j2);
table.getColumns().addAll(datecol, expeditionCol,numTrainCol,nWgsCol,totalcol,toncf,totaloncf,nTraincol,tocp,cumul);
controller.getHb().getChildren().add(table);
//chargement des données
table.setItems(data);
ArrayList<Person> tableData = new ArrayList<>();
tableData.add(new Person("Elhassani","Ayoub"));
tableData.add(new Person("Abdullah","Asendar"));
tblView.getitems().addAll(tableData);
JourSuivi j1=new JourSuivi(1,“30/04/2016”,23,34,new ArrayList(),43,new ArrayList(),345,23,2,new ArrayList(),11);
JourSuivi j2=新JourSuivi(1,“2016年4月30日”,23,34,新ArrayList(),43,新ArrayList(),345,23,2,新ArrayList(),11);
Listls=newarraylist();
增加(新吨位(1吨,“ONCF”,33);
j1.setNbWgs(ls);j2.setNbWgs(ls);
List ls_d=new ArrayList();
土地注册处增补(12.33);土地注册处增补(44.2);
j2.设置到PSA(ls_d);j1.setToncf(ls_d);j1.setToncf(ls_d);j2.setToncf(ls_d);
ObservableList data=FXCollections.observableArrayList(j1,j2);
table.getColumns().addAll(datecol、expectioncol、numTrainCol、nWgsCol、totalcol、toncf、totaloncf、nTraincol、tocp、cumul);
controller.getHb().getChildren().add(表);
//多涅斯费用
表2.设置项目(数据);

我不认为我真的理解这个问题,但这可能会有帮助:

@FXML
TableView<String> tblView; // your table view here

TableColumn<String, String> columnMain = new TableColumn<>();
columnMain.setCellValueFactory(new PropertyValueFactory<>("someValue"));
columnMain.setText("some text");

TableColumn<String, String> columnChild1 = new TableColumn<>();
columnChild1 .setCellValueFactory(new PropertyValueFactory<>("someValue"));
columnChild1 .setText("some text");

TableColumn<String, String> columnChild2 = new TableColumn<>();
columnChild2 .setCellValueFactory(new PropertyValueFactory<>("someValue"));
columnChild2 .setText("some text");

columnMain.getColumns().add(columnChild1);
columnMain.getColumns().add(columnChild2);

// columnMain now has two child columns columnChild1 and columnChild2

tblView.getColumns().add(columnMain);
如果您想联系columnChild2:

tblView.getColumns().get(0).getColumns().get(1);
编辑:

如果您想用数据填充表格,这是我的最佳方法->创建一个类来填充表格,例如:

下表:

@FXML
TableView<Person> tblView;

TableColumn<String, String> columnMain = new TableColumn<>();
columnMain.setText("Name");

TableColumn<String, String> columnChild1 = new TableColumn<>();
columnChild1 .setCellValueFactory(new PropertyValueFactory<>("firstName"));
columnChild1 .setText("First Name");

TableColumn<String, String> columnChild2 = new TableColumn<>();
columnChild2 .setCellValueFactory(new PropertyValueFactory<>("lastName"));
columnChild2 .setText("Last Name");

columnMain.getColumns().add(columnChild1);
columnMain.getColumns().add(columnChild2);

// columnMain now has two child columns columnChild1 and columnChild2

tblView.getColumns().add(columnMain);
填写表格:

JourSuivi j1=new JourSuivi(1, "30/04/2016", 23, 34, new ArrayList<>(), 43, new ArrayList<>(), 345, 23, 2, new ArrayList<>(), 11);
JourSuivi j2=new JourSuivi(1, "30/04/2016", 23, 34, new ArrayList<>(), 43, new ArrayList<>(), 345, 23, 2, new ArrayList<>(), 11);
List<Tonnage>ls=new ArrayList<>();
ls.add(new Tonnage(ls_ton,"ONCF",33));

j1.setNbWgs(ls);j2.setNbWgs(ls);
List<Double> ls_d=new ArrayList<>();
ls_d.add(12.33);ls_d.add(44.2);

j2.setTocpSA(ls_d);j1.setToncf(ls_d);j1.setToncf(ls_d);j2.setToncf(ls_d);
ObservableList<JourSuivi> data=FXCollections.observableArrayList(j1,j2);
table.getColumns().addAll(datecol, expeditionCol,numTrainCol,nWgsCol,totalcol,toncf,totaloncf,nTraincol,tocp,cumul);
controller.getHb().getChildren().add(table);
//chargement des données
table.setItems(data);
ArrayList<Person> tableData = new ArrayList<>();
tableData.add(new Person("Elhassani","Ayoub"));
tableData.add(new Person("Abdullah","Asendar"));
tblView.getitems().addAll(tableData);
ArrayList tableData=new ArrayList();
tableData.add(新增人员(“Elhassani”、“Ayoub”);
tableData.add(新增人员(“阿卜杜拉”、“阿森达尔”);
tblView.getitems().addAll(tableData);

非常感谢您的匹配。但它不起作用。事实上,我想在表中设置信息,我使用下面的代码,但在表中看不到数据;tblView.setItems(ob);但它并没有显示:demo_Result:@ElhassaniAyoub很高兴它有帮助)