Answer the question
In order to leave comments, you need to log in
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");
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;
}
table.getColumns().addAll(nameM);
root.add(table, 3, 0, 1, 5);
ObservableList<MusicStruct> list = getUserList();
table.setItems(list);
Answer the question
In order to leave comments, you need to log in
nameM.setCellValueFactory(new PropertyValueFactory("field_name_in_MusicStruct"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question