2
방금 TablView를 만들고 데이터를 입력하는 데 성공했습니다. 문제는 업데이트 할 셀을 두 번 클릭하면 업데이트 된 데이터가 표시되지만 클릭하면 업데이트 된 셀에 이전 데이터가 표시된다는 것입니다. 여기javafx 2.1 TableView 업데이트
코드 :
는table = new TableView<InvoiceLine>();
table.setEditable(true);
Callback<TableColumn, TableCell> cellFactory =
new Callback<TableColumn, TableCell>() {
public TableCell call(TableColumn p) {
return new EditingCell();
}
};
ObservableList<InvoiceLine> data = FXCollections.observableArrayList(invoice_Lines);
table.setItems(data);
designationCol = new TableColumn("Designation");
designationCol.onEditCommitProperty();
designationCol.setCellValueFactory(new PropertyValueFactory<InvoiceLine, String>("invoicelineDesignation"));
designationCol.setCellFactory(cellFactory);
designationCol.setOnEditCommit(new EventHandler<CellEditEvent<InvoiceLine, String>>() {
@Override
public void handle(CellEditEvent<InvoiceLine, String> t) {
((InvoiceLine) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setInvoicelineDesignation(t.getNewValue());
System.out.println(t.getNewValue());
}
});
TableColumn quantiteCol = new TableColumn("Quantite");
quantiteCol.setCellValueFactory(
new PropertyValueFactory<InvoiceLine, String>("invoicelineQuantity"));
quantiteCol.setCellFactory(cellFactory);
quantiteCol.setOnEditCommit(
new EventHandler<CellEditEvent<InvoiceLine, String>>() {
@Override
public void handle(CellEditEvent<InvoiceLine, String> t) {
((InvoiceLine) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setInvoicelineQuantity(t.getNewValue());
System.out.println(t.getNewValue());
}
});
TableColumn puCol = new TableColumn("Prix Unitaire");
puCol.setCellValueFactory(
new PropertyValueFactory<InvoiceLine, String>("invoicelineUnitPrice"));
puCol.setCellFactory(cellFactory);
puCol.setOnEditCommit(
new EventHandler<CellEditEvent<InvoiceLine, String>>() {
@Override
public void handle(CellEditEvent<InvoiceLine, String> t) {
((InvoiceLine) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setInvoicelineUnitPrice(t.getNewValue());
System.out.println(t.getNewValue());
}
});
TableColumn totalCol = new TableColumn("Total");
totalCol.setCellValueFactory(
new PropertyValueFactory<InvoiceLine, String>("invoicelineAmount"));
totalCol.setCellFactory(cellFactory);
totalCol.setOnEditCommit(
new EventHandler<CellEditEvent<InvoiceLine, String>>() {
@Override
public void handle(CellEditEvent<InvoiceLine, String> t) {
((InvoiceLine) t.getTableView().getItems().get(
t.getTablePosition().getRow())).setInvoicelineAmount(t.getNewValue());
System.out.println(t.getNewValue());
}
});
table.getColumns().addAll(designationCol, quantiteCol, puCol, totalCol);
centerSplitPane.setBottom(table);
}
});
누군가가 나를 도울 수하세요? thks
좋은 해결책 Uluk. JavaFX 문서 작업 팀에게 초점 변경 커밋 논리를 공식 자습서에 포함 할 것을 요청하는 이메일을 보냈습니다. – jewelsea
고마워요. 잘 작동합니다. 방금 내가 준 방법을 아래에 추가했습니다. U는 다시 한 번 멋지다. –