JavaFX TableView选定的单元格

时间:2018-07-08 19:13:08

标签: javafx tableview

有3列的表格视图

id   | stack     | amount
 1   | Древесина | 5

我需要通过按按钮将单元格的值减去1。

 ObservableList<ModelTable> oblist = FXCollections.observableArrayList();

 @Override
public void initialize(URL location, ResourceBundle resources) {

//DB

    try {
        Connection con = DBConn.getConnection();
        ResultSet rs = con.createStatement().executeQuery("select * from piles");
        while (rs.next()) {
            oblist.add(new ModelTable(rs.getString("num_pile"), rs.getString("gruz"), rs.getInt("amount")));
        }
    }catch (SQLException ex){
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }

col_id.setCellValueFactory(new PropertyValueFactory<>("id"));
col_pile.setCellValueFactory(new PropertyValueFactory<>("pile"));
col_amount.setCellValueFactory(new PropertyValueFactory<>("amount"));

table.setItems(oblist);

buttonAdd.setOnAction(e -> {

    ModelTable selectedItem = table.getSelectionModel().getSelectedItem();

    //minus 1 of cell value




});

我的英语不是很完美。希望你能理解。谢谢!

0 个答案:

没有答案