以下代码应该显示库存所有零件可观察列表中的零件。我不确定这是否是库存类未返回正确的对象,或者是否发生了其他情况,或者我在表的初始化中是否遗漏了某些内容。
编辑:我期望通过MainViewController
initializer
.class 加载PartId
、PartName
、PartStock
、 和通过类。InHouse 类扩展了 Part 类PartPrice
Inventory
observableList allParts
主视图控制器
package ViewController;
import Model.InHouse;
import Model.Inventory;
import Model.Part;
import Model.Product;
import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class MainViewController implements Initializable {
private static Inventory inventory;
//Part FXIDs
@FXML private TableView<Part> PartsTable;
@FXML private TableColumn<Part, Integer> PartId;
@FXML private TableColumn<Part, String> PartName;
@FXML private TableColumn<Part, Integer> PartStock;
@FXML private TableColumn<Part, Double> PartPrice;
//sets up the table view and loads the parts from the inventory list
public void initialize(URL url, ResourceBundle rb) {
PartId.setCellValueFactory(new PropertyValueFactory<>("PartId"));
PartName.setCellValueFactory(new PropertyValueFactory<>("PartName"));
PartStock.setCellValueFactory(new PropertyValueFactory<>("PartStock"));
PartPrice.setCellValueFactory(new PropertyValueFactory<>("PartPrice"));
inventory.addPart(new InHouse(0, "name", 5.00, 1, 1, 5, 0));
PartsTable.setItems(inventory.getAllParts());
}
}
偶然的你
相关分类