【发布时间】:2020-02-20 02:05:30
【问题描述】:
我是新来的,所以我不知道该怎么做,但我的 tableview.setitems(oblist); 有这个问题 当我启动我的程序时,表格视图不会向我显示该区域内的任何奇怪线条
public class FXMLTableController implements Initializable {
private Connection con;
@FXML
private TableView<LOC> tableview;
@FXML
private TableColumn<LOC, Integer> ttidLoc;
@FXML
private TableColumn<LOC,Integer> ttidProd;
@FXML
private TableColumn<LOC, Float> ttPrixJour;
@FXML
private TableColumn<LOC,Integer> ttMaxJour;
@FXML
private TableColumn<LOC,Integer> ttidClient;
ObservableList<LOC> oblist=FXCollections.observableArrayList();
@Override
public void initialize(URL location, ResourceBundle resources) {
try {
con = DataBase.getInstance().getConnection();
ResultSet rs = con.createStatement().executeQuery("select * from locations");
while(rs.next()) {
oblist.add(new LOC(rs.getInt("idLoc"),rs.getInt("idProd"),rs.getFloat("PrixJour"),rs.getInt("MaxJour"),rs.getInt("idClient")));
}
ttidLoc.setCellValueFactory(new PropertyValueFactory<>("idLoc"));
ttidProd.setCellValueFactory(new PropertyValueFactory<>("idProd"));
ttPrixJour.setCellValueFactory(new PropertyValueFactory<>("PrixJour"));
ttMaxJour.setCellValueFactory(new PropertyValueFactory<>("MaxJour"));
ttidClient.setCellValueFactory(new PropertyValueFactory<>("idClient"));
tableview.setItems(oblist);
} catch (SQLException ex) {
Logger.getLogger(FXMLTableController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
这是我使用的实体代码
public class LOC {
private int idLoc;
private int idProd;
private float PrixJour;
private int MaxJour;
private int idClient;
public LOC(int idLoc, int idProd, float PrixJour, int MaxJour, int idClient) {
this.idLoc = idLoc;
this.idProd = idProd;
this.PrixJour = PrixJour;
this.MaxJour = MaxJour;
this.idClient=idClient;
}
public LOC( int idProd, float PrixJour, int MaxJour, int idClient) {
this.idProd = idProd;
this.PrixJour = PrixJour;
this.MaxJour = MaxJour;
this.idClient=idClient;
顺便说一句,我正在使用场景构建器,我试图在单击第一个按钮时在另一个场景中打开 tableview
【问题讨论】:
-
您是否阅读过
PropertyValueFactory的文档并确保您的LOC类具有PropertyValueFactory所期望的方法? Edit 你的帖子包含LOC类的其余部分(最好创建一个 minimal reproducible example 来演示问题)。 -
.. 请遵守 java 命名约定 :)
-
在文档中没有明确说明,但可能需要公开这些字段才能使其工作
-
@Alex 从不公开字段。