U
U
up72018-05-22 07:12:28
Java
up7, 2018-05-22 07:12:28

How to display value in tableview cell?

I create a structure

public static TableView<MusicStruct> table = new TableView<MusicStruct>();
 public static TableColumn<MusicStruct, String> nameM = new TableColumn<MusicStruct, String>("name");

I fill in:
private ObservableList<MusicStruct> getUserList() {
 String selectTableSQL = "SELECT * from DBMUSIC";
                Connection dbConnection = null;
  Statement statement = null;
        
        ObservableList<MusicStruct> list = FXCollections.observableArrayList();
try {
  dbConnection = getDBConnection();
  statement = dbConnection.createStatement();
  ResultSet rs = statement.executeQuery(selectTableSQL); 
       int i=-1;
  while (rs.next()) {
    String namePesn = rs.getString("PESN");
    System.out.println(namePesn);
                i++;
                list.add(i, new MusicStruct(namePesn, "mp3/"+namePesn+".mp3"));           
  }
} catch (SQLException e) {
  System.out.println(e.getMessage());
}
      return list;
  }

I output:
table.getColumns().addAll(nameM);

root.add(table, 3, 0, 1, 5);

        ObservableList<MusicStruct> list = getUserList();
      table.setItems(list);

Cells are added, but nothing appears in them :( How to saddle so that they are added?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alexandrov, 2018-05-22
@up7

nameM.setCellValueFactory(new PropertyValueFactory("field_name_in_MusicStruct"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question