public ObjectProperty<Color> color = new SimpleObjectProperty<Color>();
this.color = new SimpleObjectProperty(color);
public ObjectProperty<Color> colorProperty() {
return color;
}
public void setColor(Color color2) {
color.set(color2);
}
private TableColumn<Person, String> createNameCol(){
TableColumn col = new TableColumn("Name");
col.setCellValueFactory(
new PropertyValueFactory<Person, String>("name"));
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Person, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<Person, String> t) {
Person p = t.getRowValue();
p.setName(t.getNewValue());
sl.update(p); // This is where I call the update method from my DAO.
}
});
return col;
}
2 回答
我有同样的问题CheckBoxTableCell和DatePickerTableCell和ColorPickerTableCells :-(
我这样处理它:在控件的事件中,我回到了“ ((Inputs)getTableView().getItems().get(getTableRow().getIndex() ”使用的POJO对象,我更新类似于在OnEditCommit方法中完成的...
所以对我来说它看起来像这样(更新颜色):
以下是ColorPickerCell的示例:
有了这个简单的JavaFX的POJO:
我不知道这是否是一个很好的方法来实现,但它对我有用...请注意,JavaFX的POJO只能在“ActionEvent”请求(组合框,日期选择器,颜色选择器等)中访问 .
问候,
这是我用来从tableview的可编辑单元格调用DAO的方法 .
如果这不起作用,请发布您的代码 .
EDIT:
这是一个很好的tutorial for the editable tableViews