【问题标题】:in TableView no columns appear javafx在 TableView 中没有列出现 javafx
【发布时间】:2016-12-05 14:11:25
【问题描述】:

我正在尝试将数据填充到 TableView 但不知何故它没有显示任何内容

这是我使用它作为类型创建数组列表的类:

public class movieDetails {


private String movieName;
private String description;
private String movieLocation;
private String movieTime;
private int movieThreator;

public movieDetails(String movieName, String description, String movieLocation, String movieTime, int movieThreator) {
    this.movieName = movieName;
    this.description = description;
    this.movieLocation = movieLocation;
    this.movieTime = movieTime;
    this.movieThreator = movieThreator;
}

movieDetails(String string) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public String getMovieName() {
    return movieName;
}

public String getDescription() {
    return description;
}

public String getMovieLocation() {
    return movieLocation;
}

public String getMovieTime() {
    return movieTime;
}

public int getMovieThreator() {
    return movieThreator;
}


 public void setMovieName(String movieName) {
    this.movieName=movieName;
}

public void setDescription(String description ) {
    this.description=description;
}

public void setMovieLocation(String movieLocation) {
    this.movieLocation=movieLocation;
}

public void setMovieTime(String movieTime) {
     this.movieTime=movieTime;
}

public void setMovieThreator(int movieThreator) {
    this.movieThreator=movieThreator;
}




}

然后在数据库实现类中我返回这个 ObservableList

public ObservableList movies_listView() throws ClassNotFoundException, SQLException{

    ObservableList<movieDetails>  movieDetails_Table = FXCollections.observableArrayList();   

    Class.forName(driver);
        conn = DriverManager.getConnection(url,dbuser,dbpassw);
        ResultSet rs = conn.createStatement().executeQuery("SELECT movie_name,description,cinema_location,time,threator FROM movie");

        while(rs.next()){
        movieDetails_Table.add(new movieDetails(

                            rs.getString("movie_name"),
                            rs.getString("description"),
                            rs.getString("cinema_location"),
                            rs.getString("time"),
                            rs.getInt("threator")


                             ));                                   
    }
            conn.close();


      return movieDetails_Table;  
}

在主类中

TableView<movieDetails> movieDetails_table = new TableView<>();

    TableColumn<movieDetails,String> movieNameCal=new TableColumn<>("Movie Name");
    TableColumn<movieDetails,String> movieDesCal=new TableColumn<>("Description");
    TableColumn<movieDetails,String> movieLocCal=new TableColumn<>("Movie Location");
    TableColumn<movieDetails,String> movieTimCal=new TableColumn<>("Movie Time");
    TableColumn<movieDetails,Integer> movieThreCal=new TableColumn<>("Movie Threator");


    movieNameCal.setCellValueFactory(new PropertyValueFactory<>("movie Name"));
    movieDesCal.setCellValueFactory(new PropertyValueFactory<>("description"));
    movieLocCal.setCellValueFactory(new PropertyValueFactory<>("movie Location"));
    movieTimCal.setCellValueFactory(new PropertyValueFactory<>("movie Time"));
    movieThreCal.setCellValueFactory(new PropertyValueFactory<>("movie Threator"));


movieDetails_table.getColumns().add(movieNameCal);
    movieDetails_table.getColumns().add(movieDesCal);
    movieDetails_table.getColumns().add(movieLocCal);
    movieDetails_table.getColumns().add(movieTimCal);
    movieDetails_table.getColumns().add(movieThreCal);


    deleteMovie_pane.setCenter(movieDetails_table);


 // this button to navigate the scene where the table in
deleteMovie_button.setOnAction(e->{

        try {



            movieDetails_table.setItems(db.movies_listView());
            primaryStage.setTitle("Delete Movie Scene");
            primaryStage.setScene(deleteMovie_scene);
            primaryStage.show();
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(Java_CinemaTicket.class.getName()).log(Level.SEVERE, null, ex);
        }

   });

一旦我运行 IDE 后显示没有错误,但它只显示一列填充了信息,其余的什么都没有

输出图片

这是数据库图片:

【问题讨论】:

标签: java mysql database javafx tableview


【解决方案1】:

您尚未将列添加到表中。使用

movieDetails_table.getColumns().add(movieNameCal);

等等

【讨论】:

    猜你喜欢
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多