我正在尝试在加载时填充tableview。如果有任何错误,请原谅。
public class users {
public String username;
public String FullName;
public String password;
public String phone;
public String email;
public String doj;
public String city;
public String state;
public String address;
public ObservableList <ListEmply> emplylst = FXCollections.observableArrayList();
}
public class UserDetail {
@FXML
private ObservableList <ListEmply> emplylst;
@FXML
private TableView <ListEmply> tbl_employeeview;
@FXML
private TableColumn<Object, Object> employeename;
users User = new users();
Dbconnection dbcon = new Dbconnection();
Connection con;
PreparedStatement pst;
ResultSet rs;
public void showDetails(users User){
con = dbcon.geConnection();
try{
pst = con.prepareStatement("select room_no from room");
rs = pst.executeQuery();
while (rs.next()){
User.emplylst.add(new ListEmply(
rs.getString(1)
));
}
System.out.println(rs);
rs.close();
pst.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void usrdetails(){
tbl_employeeview.setItems(emplylst);
showDetails(User);
employeename.setCellValueFactory(new PropertyValueFactory<>("employeename"));
System.out.println(rs);
}
public void Initializable(URL url, ResourceBundle rb){
usrdetails();
}
}
ListEmply Class
public class ListEmply {
public String employeename;
public ListEmply(String employeename) {
super();
this.employeename = employeename;
}
public String getEmployeename() {
return employeename;
}
}
public void setEmployeename(String employeename) {
this.employeename = employeename;
}
}
答案 0 :(得分:1)
如documentation中所述,调用初始化控制器的控制器方法称为initialize(...)
,而不是Initializable(...)
:
public void initialize(URL url, ResourceBundle rb){
usrdetails();
}
正如@fabian在评论中所指出的那样,由于您没有实现(遗留)接口Initializable
而不使用参数,您可以省略方法定义中的参数:
public void initialize(){
usrdetails();
}