Javafx 动态添加行的Tableview为空

Javafx 动态添加行的Tableview为空,javafx,Javafx,这段代码应该显示一个包含值的表,列和行被自动添加,程序的思想是在表视图中显示一个矩阵。。。不管怎样,它显示空行,解决方案是什么 private TableView MSTab; float MS[][]=new float[n][n]; for (int s = 1; s < n+1; s++){ TableColumn a = new TableColumn(Integer.toString(s));

这段代码应该显示一个包含值的表,列和行被自动添加,程序的思想是在表视图中显示一个矩阵。。。不管怎样,它显示空行,解决方案是什么

    private TableView MSTab;


    float MS[][]=new float[n][n];

 for (int s = 1; s < n+1; s++){
                    TableColumn a = new TableColumn(Integer.toString(s));

                    MSTab.getColumns().add(a);
             } 
    ObservableList<String> row = FXCollections.observableArrayList();

                 for (int l=0;l<n;l++){
                     row.removeAll(row);
                 for (int s=0;s<n;s++){

                  row.add(Float.toString(MS[l][s]));

                 }

                    MSTab.getItems().add((ObservableList) row);

                 }
private TableView MSTab;
浮动MS[][]=新浮动[n][n];
对于(int s=1;s对于(int l=0;l代码中有太多错误

SSCCE:

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class TableViewSample extends Application {

    private TableView<Person> table = new TableView<Person>();
    private final ObservableList<Person> data =
        FXCollections.observableArrayList(
            new Person("Jacob", "Smith", "jacob.smith@example.com"),
            new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
            new Person("Ethan", "Williams", "ethan.williams@example.com"),
            new Person("Emma", "Jones", "emma.jones@example.com"),
            new Person("Michael", "Brown", "michael.brown@example.com")
        );

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        stage.setTitle("Table View Sample");
        stage.setWidth(450);
        stage.setHeight(500);

        final Label label = new Label("Address Book");
        label.setFont(new Font("Arial", 20));

        table.setEditable(true);

        TableColumn firstNameCol = new TableColumn("First Name");
        firstNameCol.setMinWidth(100);
        firstNameCol.setCellValueFactory(
                new PropertyValueFactory<Person, String>("firstName"));

        TableColumn lastNameCol = new TableColumn("Last Name");
        lastNameCol.setMinWidth(100);
        lastNameCol.setCellValueFactory(
                new PropertyValueFactory<Person, String>("lastName"));

        TableColumn emailCol = new TableColumn("Email");
        emailCol.setMinWidth(200);
        emailCol.setCellValueFactory(
                new PropertyValueFactory<Person, String>("email"));

        table.setItems(data);
        table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);

        final VBox vbox = new VBox();
        vbox.setSpacing(5);
        vbox.setPadding(new Insets(10, 0, 0, 10));
        vbox.getChildren().addAll(label, table);

        ((Group) scene.getRoot()).getChildren().addAll(vbox);

        stage.setScene(scene);
        stage.show();
    }

    public static class Person {

        private final SimpleStringProperty firstName;
        private final SimpleStringProperty lastName;
        private final SimpleStringProperty email;

        private Person(String fName, String lName, String email) {
            this.firstName = new SimpleStringProperty(fName);
            this.lastName = new SimpleStringProperty(lName);
            this.email = new SimpleStringProperty(email);
        }

        public String getFirstName() {
            return firstName.get();
        }

        public void setFirstName(String fName) {
            firstName.set(fName);
        }

        public String getLastName() {
            return lastName.get();
        }

        public void setLastName(String fName) {
            lastName.set(fName);
        }

        public String getEmail() {
            return email.get();
        }

        public void setEmail(String fName) {
            email.set(fName);
        }
    }
} 
导入javafx.application.application;
导入javafx.beans.property.SimpleStringProperty;
导入javafx.collections.FXCollections;
导入javafx.collections.ObservableList;
导入javafx.geometry.Insets;
导入javafx.scene.Group;
导入javafx.scene.scene;
导入javafx.scene.control.Label;
导入javafx.scene.control.TableColumn;
导入javafx.scene.control.TableView;
导入javafx.scene.control.TextField;
导入javafx.scene.control.cell.PropertyValueFactory;
导入javafx.scene.layout.VBox;
导入javafx.scene.text.Font;
导入javafx.stage.stage;
公共类TableViewSample扩展了应用程序{
private TableView table=new TableView();
私有最终可观测列表数据=
FXCollections.observableArrayList(
新人(“雅各布”、“史密斯”、“雅各布”。smith@example.com"),
新人(“伊莎贝拉”、“约翰逊”、“伊莎贝拉”。johnson@example.com"),
新人(“伊桑”、“威廉姆斯”、“伊桑”。williams@example.com"),
新人(“艾玛”、“琼斯”、“艾玛”。jones@example.com"),
新人(“迈克尔”、“布朗”、“迈克尔”。brown@example.com")
);
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
公众假期开始(阶段){
场景=新场景(新组());
stage.setTitle(“表格视图示例”);
舞台布景宽度(450);
舞台设置高度(500);
最终标签=新标签(“地址簿”);
label.setFont(新字体(“Arial”,20));
table.setEditable(true);
TableColumn firstNameCol=新的TableColumn(“名字”);
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
新财产价值工厂(“名字”);
TableColumn lastNameCol=新的TableColumn(“姓氏”);
lastNameCol.setMinWidth(100);
lastNameCol.setCellValueFactory(
新财产价值工厂(“姓氏”);
TableColumn emailCol=新的TableColumn(“电子邮件”);
设置最小宽度(200);
emailCol.setCellValueFactory(
新物业价值工厂(“电子邮件”);
表2.设置项目(数据);
table.getColumns().addAll(firstNameCol、lastNameCol、emailCol);
最终VBox VBox=新的VBox();
vbox.setspace(5);
设置填充(新的插入(10,0,0,10));
vbox.getChildren().addAll(标签、表格);
((组)scene.getRoot()).getChildren().addAll(vbox);
舞台场景;
stage.show();
}
公共静态类人员{
私有最终SimpleStringProperty名字;
私有最终SimpleStringProperty姓氏;
私人最终SimpleStringProperty电子邮件;
私人(字符串fName、字符串lName、字符串电子邮件){
this.firstName=新的SimpleStringProperty(fName);
this.lastName=新的SimpleStringProperty(lName);
this.email=新的SimpleStringProperty(电子邮件);
}
公共字符串getFirstName(){
返回firstName.get();
}
public void setFirstName(字符串fName){
firstName.set(fName);
}
公共字符串getLastName(){
返回lastName.get();
}
public void setLastName(字符串fName){
lastName.set(fName);
}
公共字符串getEmail(){
返回email.get();
}
public void setEmail(字符串fName){
email.set(fName);
}
}
} 

OH my good!!该代码不是全部代码,在编译时没有问题,你没有问题!!看看你的代码,你已经将列数固定为3作为“Person”有3个参数,…但我想有一个有n列的表,n可以取任何值,而不仅仅是3…所以谢谢你,如果你没有答案,请删除这个…1.做一个2.用更精确的术语说明你的问题所在。向我们展示你的尝试。3.停止命令我。-咬紧牙关好的,谢谢你,我很感激那我就做SSCCE;)