4
隨着我的應用程序的增長,我想創建額外的類來處理sql查詢,數據驗證等。目前,控制器管理這一切。使用場景構建器和多個控制器
但是,我不知道如何去創建不同的類,可以與我的控制器類中的組件以及我的.fxml文件「交談」。
我attemped這樣的:JavaFX 1 FXML File with Multiple Different Controllers?
..和嘗試創建一個新的類來填充表如下:
import java.sql.Connection;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class DepartmentTable {
private Connection conn;
private FXMLLoader fxmlLoader;
@FXML
private TableView<Department> departmentTableView;// = new TableView<>(staffTypeList);
@FXML
private TableColumn<Department, Integer> departmentIdCol;
@FXML
private TableColumn<Department, String> departmentNameCol;
private ObservableList<Department> departmentList;
public DepartmentTable(Connection aconn, FXMLLoader loader) {
this.conn = aconn;
this.fxmlLoader=loader;
loadController();
populateDepartmentTable();
}
private void loadController(){
fxmlLoader.setController(this);
}
private void populateDepartmentTable() {
departmentList = new DepartmentData(conn).getDepartmentList();
/*Populate the Table with StaffType objects*/
departmentIdCol.setCellValueFactory(
new PropertyValueFactory<Department, Integer>("departmentID"));
departmentNameCol.setCellValueFactory(
new PropertyValueFactory<Department, String>("departmentName"));
departmentTableView.setItems(departmentList);
}
}
不過,我得到它由一個NullPointerException在
引起了的InvocationTargetException/*Populate the Table with StaffType objects*/
departmentIdCol.setCellValueFactory(
所以我不知道該怎麼做。
請幫忙。謝謝!
謝謝!!!忘記標記 –