Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建ObservableList数组并在JavaFX表的循环中初始化它们_Java_Arrays_Javafx_Observablelist - Fatal编程技术网

如何创建ObservableList数组并在JavaFX表的循环中初始化它们

如何创建ObservableList数组并在JavaFX表的循环中初始化它们,java,arrays,javafx,observablelist,Java,Arrays,Javafx,Observablelist,我正在尝试创建一个模拟不同锦标赛的锦标赛应用程序。我正在使用javaFX。这里的问题是,我想显示不同组阶段的几个表,即组1、组2等。。我已经创建了一个表和表列的数组,所有的工作都很好,但是我不知道如何创建一个observeList对象数组来传递到相应的表中。我想在一个循环中创建ObservableList数组,并初始化循环中的变量以使其灵活。以下是我的控制器类的代码: package com.solutioninventors.tournament.GUI.StandingTable.copy;

我正在尝试创建一个模拟不同锦标赛的锦标赛应用程序。我正在使用javaFX。这里的问题是,我想显示不同组阶段的几个表,即组1、组2等。。我已经创建了一个表和表列的数组,所有的工作都很好,但是我不知道如何创建一个
observeList
对象数组来传递到相应的表中。我想在一个循环中创建
ObservableList
数组,并初始化循环中的变量以使其灵活。以下是我的控制器类的代码:

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]; 
           for (int i = 0; i < name.length; i++) {
                 name[i] = new TableColumn<>("Competitor Name");
                 name[i].setMinWidth(200);
                 name[i].setCellValueFactory(new PropertyValueFactory<>("competitorName"));
            }//end for loop for name setup

           WDLFADP = new TableColumn[noOfRounds][8];  
           for (int row = 0; row < WDLFADP.length; row++) {
                for (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 a way to make this list1 and list2 in an array
          // and initalize them in a loop as 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 do I pass in multiple list
        for (int i = 0; i < table.length; i++) {
            table[i] = new TableView<>();
            table[i].setItems(list);//here is the problem
            table[i].getColumns().add(name[i]);
            for (int col = 0; col < WDLFADP[i].length; col++) {
                table[i].getColumns().add(WDLFADP[i][col]);
            }
        }//end outer for loop
    }// end table setup



    @Override
    public void initialize(URL location, ResourceBundle resources) {
        setupTable();//call utility method
        Label lbl[] = new Label[noOfRounds];
        for (int i = 0; i < lbl.length; i++) {
            lbl[i] = new Label("Group "+(i+1));
        }
        vBox = new VBox();
        vBox.setPadding(new Insets(10, 10, 10, 10));
        for (int i = 0; i < noOfRounds; i++) {
            vBox.getChildren().add(lbl[i]);
            vBox.getChildren().add(table[i]);
        }//end for loop
        sp.setContent(vBox);
    }

}// end class
package com.solutioninventors.tournament.GUI.StandingTable.copy;
导入java.net.URL;
导入java.util.ResourceBundle;
导入javax.swing.text.StyledEditorKit.ForegroundAction;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入javafx.fxml.fxml;
导入javafx.fxml.Initializable;
导入javafx.geometry.Insets;
导入javafx.scene.control.Button;
导入javafx.scene.control.Label;
导入javafx.scene.control.ScrollPane;
导入javafx.scene.control.TableColumn;
导入javafx.scene.control.TableView;
导入javafx.scene.control.cell.PropertyValueFactory;
导入javafx.scene.layout.VBox;
/**
*@author-ChineduKnight
*/
公共类StandingTableController实现可初始化{
@FXML
滚动窗格sp;
TableView表格[];
表列名称[];
表列WDLFADP[]];
字符串tableLabel[]={“P”、“W”、“D”、“L”、“GF”、“GA”、“GD”、“PTS”};
String standingTableValue[]={“gamesPlayed”、“wins”、“draw”、“loss”、“goalsFor”、“goalscountry”、“goalsDiff”、“points”};
int noOfRounds=3;
专用VBox VBox;
@抑制警告(“未选中”)
公共void setupTable(){
name=新表列[noOfRounds];
for(int i=0;i
不能创建泛型对象类型的数组。创建一个
列表
。@James\u感谢您的快速响应,我尝试了您的答案,但我在实例化方面仍然有问题,即如何将值传递到列表您无法创建泛型对象类型的数组。改为创建一个
列表
。@James\u感谢您的快速响应,我尝试了您的答案,但我在实例化方面仍然有问题,即如何将值传递到列表中