表视图不显示javafx中的数据

时间:2014-12-13 18:25:46

标签: javafx mixlib-shellout

我已经制作了正确的代码但没有显示结果。

表格是空的还是隐藏在最后?

public class 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>

当我打印行时,我看到了结果,但是当我在表格中设置它时没有。

是我的所有代码

0 个答案:

没有答案