2016-04-15 20 views
0

Ich möchte Informationen in der Tabellenansicht, die einen geschachtelten Header hat, wie Excel-Tabelle festlegen. Aber ich stundenlang, ohne etwas bekommen, die mir helfen kannWie behandeln Informationen in der Tabellenansicht, die Nested Header haben?

Das Ergebnis, das ich brauche, ist wie folgt:

enter image description here

aber derzeit sieht aus wie folgt:

I can't see all information

Mein Code zum Setzen von Informationen in die Tabelle:

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); 

Antwort

0

ich denke nicht, dass ich wirklich die Frage verstehen, aber diese helfen könnten:

@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); 

wenn Sie erreichen columnChild1 wollen:

tblView.getColumns().get(0).getColumns().get(0); 

wenn Sie columnChild2 erreichen wollen:

tblView.getColumns().get(0).getColumns().get(1); 

bearbeiten:

, wenn Sie die Tabelle mit Daten füllen wollen, ist dies der beste Weg für mich -> eine Klasse erstellen, die Tabelle mit, ex zu füllen:

die Tabelle:

@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); 

und das Objekt:

public class Person{ 
     String firstName; 
     String lastName; 
     public Person(String firstName,String lastName){ 
      this.firstName=firstName; 
      this.lastName=lastName; 
    } 
} 

die Tabelle ausfüllen:

ArrayList<Person> tableData = new ArrayList<>(); 
tableData.add(new Person("Elhassani","Ayoub")); 
tableData.add(new Person("Abdullah","Asendar")); 
tblView.getitems().addAll(tableData); 
+0

u sehr Match danken .aber es nicht eisernes. In der Tat möchte ich Informationen in der Tabelle setzen, und ich benutze den Code unten, aber ich sehe keine Daten in der Tabelle. –

+0

Der Code zum Einstellen von Informationen ist wie folgt: –

+0

ObservableList ob = FXCollections.observableArrayList ("gagga", "bbbd", "hdgdgd"); \t \t tblView.setItems (ob); –

Verwandte Themen