首页 > 解决方案 > 在 javafx 中获得比需要更多的行数。如何解决这个问题?

问题描述

我正在尝试创建一个包含一些数据的表,但是,得到的空行比需要的多。

显示了我需要的信息,并且额外的行显示了如何删除这些信息?

试图将其保持在窗格的高度但未解决。

表样例.java

public class TableSample extends Application {
TableView<Product> table;
    @Override
    public void start(Stage primaryStage) throws Exception {

        TableColumn<Product,String> nameColoumn = new TableColumn<>("Name");
        nameColoumn.setMinWidth(200);
        nameColoumn.setCellValueFactory(new PropertyValueFactory<>("name"));

        TableColumn<Product,Double> priceColoumn = new TableColumn<>("Price");
        priceColoumn.setMinWidth(200);
        priceColoumn.setCellValueFactory(new PropertyValueFactory<>("price"));

        TableColumn<Product,Integer> quatityColoumn = new TableColumn<>("Quantity");
        quatityColoumn.setMinWidth(200);
        quatityColoumn.setCellValueFactory(new PropertyValueFactory<>("quatity"));


        table=new TableView<>();
        table.setItems(getProduct());
        table.getColumns().addAll(nameColoumn,priceColoumn,quatityColoumn);


        VBox vbox = new VBox();
        vbox.getChildren().add(table);
        Scene scene = new Scene(vbox);

        primaryStage.setScene(scene);

        primaryStage.show();
    }
    public ObservableList<Product> getProduct(){
        ObservableList<Product> products =FXCollections.observableArrayList();
        products.add(new Product("laptopt",55,22));
        products.add(new Product("sjkad",56,52));
        products.add(new Product("qqqqq",42,52));
        products.add(new Product("ddd",25,42));
        products.add(new Product("www",72,5225));

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

标签: javajavafx

解决方案


推荐阅读