java - How to create an array of ObservableList and initialize them in a loop for JavaFX Table -
i trying create tournament application simulates different tournament. using javafx. question here want display several tables different group stages i.e. group 1, group2 etc.. have created array of tables , table columns , works don't know how create array of observablelist
objects pass respective table. want create array of observablelist
in loop , initialize variables in loop make flexible. here code of controller class:
package com.solutioninventors.tournament.gui.standingtable.copy; import java.net.url; import java.util.resourcebundle; import javax.swing.text.stylededitorkit.foregroundaction; import javafx.collections.fxcollections; import javafx.collections.observablelist; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.geometry.insets; import javafx.scene.control.button; import javafx.scene.control.label; import javafx.scene.control.scrollpane; import javafx.scene.control.tablecolumn; import javafx.scene.control.tableview; import javafx.scene.control.cell.propertyvaluefactory; import javafx.scene.layout.vbox; /** * @author chineduknight */ public class standingtablecontroller implements initializable { @fxml scrollpane sp; tableview<standingtable> table[]; tablecolumn<standingtable, string> name[]; tablecolumn<standingtable, double> wdlfadp[][]; string tablelabel[] = {"p","w","d","l","gf","ga","gd","pts"}; string standingtablevalue[] = {"gamesplayed","wins","draw","loss","goalsfor","goalsagainst","goalsdiff","points"}; int noofrounds = 3; private vbox vbox; @suppresswarnings("unchecked") public void setuptable() { name = new tablecolumn[noofrounds]; (int = 0; < name.length; i++) { name[i] = new tablecolumn<>("competitor name"); name[i].setminwidth(200); name[i].setcellvaluefactory(new propertyvaluefactory<>("competitorname")); }//end loop name setup wdlfadp = new tablecolumn[noofrounds][8]; (int row = 0; row < wdlfadp.length; row++) { (int col = 0; col < wdlfadp[row].length; col++) { wdlfadp[row][col] = new tablecolumn<>(tablelabel[col]); wdlfadp[row][col].setminwidth(5); wdlfadp[row][col].setcellvaluefactory(new propertyvaluefactory<>(standingtablevalue[col])); } } //is there way make list1 , list2 in array // , initalize them in loop well? observablelist<standingtable> list = fxcollections.observablearraylist( new standingtable("manu", 5, 2, 4, 3, 4, 2, 3, 4), new standingtable("arsenal", 5, 2, 4, 3, 4, 2, 3, 4), new standingtable("chelsea", 5, 2, 4, 3, 4, 2, 3, 4) ); observablelist<standingtable> list2 = fxcollections.observablearraylist( new standingtable("everton", 5, 2, 4, 3, 4, 2, 3, 4), new standingtable("liverpool", 5, 2, 4, 3, 4, 2, 3, 4), new standingtable("mancity", 5, 2, 4, 3, 4, 2, 3, 4) ); table = new tableview[noofrounds]; //how pass in multiple list (int = 0; < table.length; i++) { table[i] = new tableview<>(); table[i].setitems(list);//here problem table[i].getcolumns().add(name[i]); (int col = 0; col < wdlfadp[i].length; col++) { table[i].getcolumns().add(wdlfadp[i][col]); } }//end outer loop }// end table setup @override public void initialize(url location, resourcebundle resources) { setuptable();//call utility method label lbl[] = new label[noofrounds]; (int = 0; < lbl.length; i++) { lbl[i] = new label("group "+(i+1)); } vbox = new vbox(); vbox.setpadding(new insets(10, 10, 10, 10)); (int = 0; < noofrounds; i++) { vbox.getchildren().add(lbl[i]); vbox.getchildren().add(table[i]); }//end loop sp.setcontent(vbox); } }// end class
Comments
Post a Comment