Combobox 提交编辑不';不要调用setOneditCommit
我的项目中有一个问题。Combobox 提交编辑不';不要调用setOneditCommit,combobox,javafx,tableview,Combobox,Javafx,Tableview,我的项目中有一个问题。 我想用comboBox构建一个tableColum,为此我使用: tableColumn.setCellFactory(ComboBoxTableCell.forTableColumn(cbValues)); 这是可行的,但正如博士所说: 默认情况下,ComboBoxTableCell在未编辑时呈现为标签,在编辑模式下呈现为ComboxBox 但是我希望每次都能看到组合框,所以我构建了这段代码 tableColumn.setCellFactory(new Callbac
我想用comboBox构建一个tableColum,为此我使用:
tableColumn.setCellFactory(ComboBoxTableCell.forTableColumn(cbValues));
这是可行的,但正如博士所说:
默认情况下,ComboBoxTableCell在未编辑时呈现为标签,在编辑模式下呈现为ComboxBox
但是我希望每次都能看到组合框,所以我构建了这段代码
tableColumn.setCellFactory(new Callback<TableColumn<Ambientale, Integer>, TableCell<Ambientale, Integer>>() {
@Override
public TableCell<Ambientale, Integer> call(TableColumn<Ambientale, Integer> param) {
return new ComboBoxCell(cbValues);
}
});
tableColumn.setCellFactory(新回调(){
@凌驾
公共TableCell调用(TableColumn参数){
返回新的ComboBoxCell(cbValues);
}
});
我的ComboBoxCell是:
class ComboBoxCell extends TableCell<Ambientale, Integer> implements Callback<Object, Object>{
private ComboBox combo;
public ComboBoxCell() {
combo = new ComboBox();
}
public ComboBoxCell(ObservableList items) {
combo = new ComboBox();
combo.setItems(items);
combo.setOnAction(new EventHandler() {
@Override
public void handle(Event event) {
System.out.println(" it's works");
commitEdit((Integer)combo.getSelectionModel().getSelectedItem());
}
});
}
@Override
public void updateItem(Integer item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
combo.getSelectionModel().select(item);
setGraphic(combo);
setContentDisplay(ContentDisplay.CENTER);
}
}
@Override
public Object call(Object param) {
return new ComboBoxCell();
}
}
类ComboBoxCell扩展TableCell实现回调{
私人组合框组合;
公共ComboxCell(){
combo=新的组合框();
}
公共ComboxCell(可观察列表项){
combo=新的组合框();
combo.setItems(项目);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(事件){
System.out.println(“它的作品”);
committedit((整数)combo.getSelectionModel().getSelectedItem());
}
});
}
@凌驾
public void updateItem(整数项,布尔空){
super.updateItem(项,空);
if(空){
setText(空);
设置图形(空);
}否则{
combo.getSelectionModel().select(项);
设置图形(组合);
setContentDisplay(ContentDisplay.CENTER);
}
}
@凌驾
公共对象调用(对象参数){
返回新的ComboBoxCell();
}
}
问题就在这里
class ComboBoxCell extends TableCell<Ambientale, Integer> implements Callback<Object, Object>{
private ComboBox combo;
public ComboBoxCell() {
combo = new ComboBox();
}
public ComboBoxCell(ObservableList items) {
combo = new ComboBox();
combo.setItems(items);
combo.setOnAction(new EventHandler() {
@Override
public void handle(Event event) {
System.out.println(" it's works");
commitEdit((Integer)combo.getSelectionModel().getSelectedItem());
}
});
}
@Override
public void updateItem(Integer item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
combo.getSelectionModel().select(item);
setGraphic(combo);
setContentDisplay(ContentDisplay.CENTER);
}
}
@Override
public Object call(Object param) {
return new ComboBoxCell();
}
类ComboBoxCell扩展TableCell实现回调{
私人组合框组合;
公共ComboxCell(){
combo=新的组合框();
}
公共ComboxCell(可观察列表项){
combo=新的组合框();
combo.setItems(项目);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(事件){
System.out.println(“它的作品”);
committedit((整数)combo.getSelectionModel().getSelectedItem());
}
});
}
@凌驾
public void updateItem(整数项,布尔空){
super.updateItem(项,空);
if(空){
setText(空);
设置图形(空);
}否则{
combo.getSelectionModel().select(项);
设置图形(组合);
setContentDisplay(ContentDisplay.CENTER);
}
}
@凌驾
公共对象调用(对象参数){
返回新的ComboBoxCell();
}
}
CommitteIt(…)不调用:
tableColumn.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<Ambientale, Integer>>() {
@Override
public void handle(TableColumn.CellEditEvent<Ambientale, Integer> t) { //aggiornare database cella singola
System.out.println("not called");
//other stuffs
}
});
tableColumn.setOnEditCommit(新的EventHandler(){
@凌驾
public void句柄(TableColumn.CellEditEvent t){//aggiornare数据库cella singola
System.out.println(“未调用”);
//其他东西
}
});
你能帮帮我吗。它行得通,我不知道为什么,但它行得通。
我已经在我的ComboBoxCell上添加了这个
combo.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
getTableView().edit(getIndex(), getTableColumn());
} else {
commitEdit((Integer)combo.getSelectionModel().getSelectedItem());
}
}
});
combo.focusedProperty().addListener(新的ChangeListener()){
@凌驾
public void已更改(observeValueI猜测这是因为您没有在右侧的tablecolumn上设置onEditCommit。请尝试tablecolumn.setOnEditCommit(…);已编辑,这在这个问题上是一个小错误,而不是在代码上。但是tnx