JavaFX,SceneBuilder,使用MySQL结果集填充TableView

时间:2015-09-01 14:39:48

标签: mysql javafx tableview scenebuilder

在学习FX / FXML时,我终于在代码中用NPE克服了我的问题。我现在有一个不同的问题,一个窗口打开我的TableView,但表中根本没有内容。随着你的忙,我已打印出JobList以确保返回内容,并返回三个作业(正确的数量)。我错过了将表绑定到返回列表的内容吗?

这是代码;

public class SecondInterface implements Initializable {

    private JobDataAccessor jAccessor;
    private String aQuery = "SELECT * FROM progdb.adamJobs";
    private Parent layout;
    private Connection connection;
    @FXML
    TableView<Job> tView;

    public void newI(Connection connection) throws Exception {

        Stage primaryStage;
        primaryStage = MainApp.primaryStage;

        this.connection = connection;
        System.out.println(connection);

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Test1.fxml"));
        fxmlLoader.setController(this);

        try {
            layout = (Parent) fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }

        primaryStage.getScene().setRoot(layout);
    }

    public Parent getLayout() {
        return layout;
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        jAccessor = new JobDataAccessor();

        try {
            System.out.println("This connection: " + connection);
            System.out.println("This query: " + aQuery);
            List<Job> jList = jAccessor.getJobList(connection, aQuery);
            for (Job j : jList) {
                System.out.println(j);
            }
            tView.getItems().addAll(jAccessor.getJobList(connection, aQuery));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

0 个答案:

没有答案