我已经编写了正确的代码,但没有显示结果。
表是空的还是最后隐藏的?
公共类 FXMLResultController 实现 Initializable {
@FXML
//You shouldn't make a new TableView
//TableView Tblresult = new TableView();
//Just declare it since it's already made in the FXML file
TableView Tblresult;
@FXML
TableColumn col;
@FXML
ResultSet Rs = null;
@FXML
public ComboBox reportcombo;
@FXML
int id = 1;
@FXML
public void SelectItem(ActionEvent event) throws SQLException {
ObservableList data = FXCollections.observableArrayList();
ObservableList row=null;
// ObservableList row = FXCollections.observableArrayList();
//ListView<String> a = new ListView<String>();
// ArrayList row = new ArrayList();
// ResultSetMetaData row;
id = reportcombo.getSelectionModel().getSelectedIndex();
String Query = null;
switch (id) {
case 0:
Query = "select * from book";
break;
case 1:
Query = "select sum(price) from book";
break;
case 2:
Query = "select count(*) as tedad,title from book group by title";
break;
case 3:
Query = "select * from book()";
break;
case 4:
Query = "select * from book where";
break;
case 5:
Query = "select * from book";
break;
case 6:
Query = "select * from book";
break;
case 7:
Query = "select * from book";
break;
case 8:
Query = "select * from book";
break;
case 9:
Query = "select * from book";
break;
case 10:
Query = "select * from book";
break;
case 11:
Query = "select * from book";
break;
case 12:
Query = "select * from book";
break;
case 13:
Query = "select * from book";
break;
}
Rs = DB_Model.Exequte_Query(Query);
Rs.beforeFirst();
int counter = 1;
Tblresult.getColumns().clear();
while (Rs.next()) {
row = FXCollections.observableArrayList();
row.add(Rs.getString(counter));
data.add(row);
col = new TableColumn(Rs.getMetaData().getColumnName(counter));
Tblresult.getColumns().add(col);
col.setCellValueFactory(new PropertyValueFactory<Object,Object>(Rs.getMetaData().getColumnName(counter)));
counter++;
}
Tblresult.getItems().setAll(data);
Tblresult.setItems(data);
Tblresult.setVisible(true);
for (int i = 1; i <= 4; i++) {
System.err.println(data);
}
}
}
FXML.fxml 文件:
Fxml 文件:
<TableView fx:id="Tblresult" layoutX="1.0" layoutY="262.0" prefHeight="256.0" prefWidth="692.0">
</TableView>
当我打印该行时,我看到了结果,但当我将它设置在表格中时却没有。
这是我的所有代码