javafx:数据未显示在tableview

时间:2018-01-24 21:09:17

标签: java javafx

学校项目的库存系统 链接到完整代码: https://www.dropbox.com/s/7dqfwmx6gwrenj4/MattNapper.zip?dl=0

未从InventoryController(ObservableList -Part- allParts )获取数据以更正“HomePageController”表(partsTable)。假数据使用InhousePart实例。 InHousePart和OutsourcedPart扩展了Part(摘要)

public class Inventory {

//declaring arrays for parts, and products
private ObservableList<Product> products = FXCollections.observableArrayList();
private ObservableList<Part> allParts = FXCollections.observableArrayList();



//fake data
InHousePart part1 = new InHousePart (1, 1, "pick", 10.00, 1, 1, 5 );

//adds fake data to "allParts" arraylist
public void addData() {
    allParts.add(part1);
}
 //return method for allParts
  public ObservableList<Part> getPartData() {
    return allParts;
}

表所在的HomepageController

**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    partID.setCellValueFactory(cellData -> cellData.getValue().partIDProperty().asObject());
    partName.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
    InvLvl.setCellValueFactory(cellData -> cellData.getValue().InStockProperty().asObject());
    pCPU.setCellValueFactory(cellData -> cellData.getValue().priceProperty().asObject());
}   


//private Inventory myInv;  is declared above at top

public void setPartsTable(Inventory myInv) {
    this.myInv = myInv;
    // Add array list data to the table

    partsTable.setItems(myInv.getPartData());

}

}

MainApp在start中调用showPartsView()。 showPartsView()通过rootLayout加载主页,amd让主页控制器访问主应用程序。还没有来自库存类的数据

@Override
public void start(Stage stage) throws Exception {
    this.stage = stage;
    this.stage.setTitle("MattNapper");
//calling func
      initRootLayout();
      showPartsView();

}

/**
 * Initializes the root layout.
 */
public void initRootLayout() {
    try {
         //Load root layout from fxml file.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("View_Controller/RootLayout.fxml"));
        rootLayout = (BorderPane) loader.load();

        // Show the scene containing the root layout.
        Scene scene = new Scene(rootLayout);
        stage.setScene(scene);
        stage.show();


    } catch (IOException e) {
        e.printStackTrace();
    }
}

/**
 * Shows the animal overview inside the root layout.
 */
public void showPartsView() {
    try {
        // Load homepage overview.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource("View_Controller/HomePage.fxml"));
        AnchorPane homepage = (AnchorPane) loader.load();

        // Set animal overview into the center of root layout.
        rootLayout.setCenter(homepage);

     // Give the controller access to the main app.
    HomePageController controller = loader.getController();
    controller.setPartsTable(inv);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案