javafx - 使用不同列中的 TextField 编辑 JavaFx TableView 单元格
问题描述
我有包含 3 列的 TableView,其中两个是用 TextFields 编辑的,以允许用户在其中输入数据,但是当我从表中检索项目时,它会返回未进入 TextFields 的内容,如图像中不返回单元格中的正确数字
这是我的代码:
编辑我发现我的 ObservableList(数据)中的问题我向 TextField 添加了操作以使用新值更新数据,但是如何使代码更新不同的行,因为它使用 TextField 中的最后一个值更新值并摆脱按下ENTER 获取 TxtField 中的整个值,因为它忽略最后一个字符,例如,如果在 TxtField 中输入“30”,我得到“3”而不是“30”
productQuantity.setCellFactory(new Callback <TableColumn, TableCell> ()
{
@Override
public TableCell call(TableColumn param)
{
return new TableCell()
{
private TextField txtProductQuantity;
@Override
protected void updateItem(Object item, boolean empty)
{
super.updateItem(item, empty);
if(!empty)
{
setGraphic(getTextField());
}
else
{
setGraphic(null);
}
}
public TextField getTextField()
{
if(txtProductQuantity == null)
{
txtProductQuantity = new TextField();
txtProductQuantity.setAlignment(Pos.BASELINE_RIGHT);
txtPurchaseItemPrice.setOnKeyPressed(e ->
{
data.get(0).setPurchaseItemPrice(txtPurchaseItemPrice.getText());
});
}
return txtProductQuantity;
}
};
}
});
productQuantity.setOnEditCommit(new EventHandler<CellEditEvent<ProductOpeningBalance, String>> ()
{
@Override
public void handle(CellEditEvent<ProductOpeningBalance, String> t)
{
((ProductOpeningBalance)
t.getTableView().getItems().get(t.getTablePosition().getRow())
).setProductQuantity(t.getNewValue());
}
});
从表中检索数据的代码
size = tableProductOpeningBalance.getItems().size();
for(int i = 0; i < size; i++)
{
System.out.println(tableProductOpeningBalance.getItems().get(i).getPurchaseItemPrice());
}
请帮忙?
解决方案
推荐阅读
- python - Python pandas 数据帧事务
- hadoop-yarn - nodelabel 作业中的资源使用情况
- node.js - Sequelize truncate 方法丢弃表
- kubernetes - Kubernetes 作业完成时自动删除持久卷声明
- python - 如何在不弄乱序列的情况下将列表转换为字典
- ios - 对“FIRDataEventTypeChildAdded”的引用不明确
- android - 更新了 Android Studio 现在我的应用程序因从未见过的错误而崩溃
- java - Java - BufferedWriter.write() 和 System.out.println() 的区别?
- python - 保存和读取加倍而没有精度损失
- content-management-system - 如何使用 AppDrag CMS 创建弹出窗口?