gpt4 book ai didi

mysql - 我的表格 View 中只填充了一列

转载 作者:行者123 更新时间:2023-11-29 21:00:34 26 4
gpt4 key购买 nike

我正在从 mysql 数据库填充 TableView ,但只有列 ID 是唯一填充的。

我的主要:

        public void populate() throws Exception{

ObservableList<userdata1> data = FXCollections.observableArrayList();

tableView();

try{
String query = "select * from members";
ps = new Connect().connectDatabase1();
rs = ps.executeQuery(query);
while(rs.next()){
data.add(new userdata1(rs.getInt(1),rs.getString(2),rs.getInt(3)));
tblView.setItems(data);
}


}catch(Exception e){
System.out.print("asdqweasd");

}
}


public void tableView()throws Exception{
tblView.getItems().clear();
tblView.getColumns().clear();
rs = ps.executeQuery("SELECT * FROM members");
ObservableList<userdata1> data = FXCollections.observableArrayList();
TableColumn column1 = new TableColumn("ID");
column1.setMinWidth(85);
column1.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("ID"));
TableColumn column2 = new TableColumn("Name");
column2.setMinWidth(565);
column2.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("comp_name"));
TableColumn column3 = new TableColumn("STATUS");
column3.setMinWidth(123);
column3.setCellValueFactory(new javafx.scene.control.cell.PropertyValueFactory<>("mem_status"));



tblView.getColumns().addAll(column1,column2,column3);

}

我的用户数据1:

public class userdata1 {
public SimpleIntegerProperty ID;
public SimpleStringProperty comp_name;
public SimpleIntegerProperty mem_status;

public userdata1(Integer id, String comp_name, Integer mem_status){
this.ID = new SimpleIntegerProperty(id);
this.comp_name = new SimpleStringProperty(comp_name);
this.mem_status = new SimpleIntegerProperty(mem_status);

}
public Integer getID() {
return ID.get();
}

public String getcomp_name(){
return comp_name.get();
}

public Integer getmem_status() {
return mem_status.get();
}


public void setID(Integer id) {

this.ID.set(id);
}

public void setcomp_name(String comp_name ) {
this.comp_name.set(comp_name);
}

public void setmem_status(Integer mem_status) {

this.mem_status.set(mem_status);
}
}

数据 mem_status 和 comp_name 未填充各自的列

最佳答案

由于UserData1已经包含Properties,您可以将相应的Property设置为cellValueFactory:

public class UserData1 {
private StringProperty comp_name;
//additional fields, getters and setters

public StringProperty comp_nameProperty() {
return comp_name;
}
}


setCellValueFactory(cellData -> cellData.getValue().comp_nameProperty());

如果您想坚持使用 PropertyValueFactory,您必须根据 CamelCase 约定访问字段:

column2.setCellValueFactory(new PropertyValueFactory<>("comp_name"));


public class UserData1 {
//...
public String getComp_name(){
return comp_name.get();
}
}

关于mysql - 我的表格 View 中只填充了一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37267281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com