问题描述
我将以下单元格工厂应用到列。
I'm applying the below cell factory to a column.
targetEnviroment.setCellFactory(new Callback<TableColumn<DevWorkTabBench, String>, TableCell<DevWorkTabBench, String>>() {
@Override
public TableCell<DevWorkTabBench, String> call(TableColumn<DevWorkTabBench, String> param) {
TableCell<DevWorkTabBench, String> cell = new TableCell<DevWorkTabBench, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
String status = null;
try {
status = getTableView().getItems().get(getIndex()).getObjectStatus();
} catch (IndexOutOfBoundsException ex) {
status = "";
}
if (status.equalsIgnoreCase("ReadyForDeployment")) {
ComboBox<String> comboBox = new ComboBox(environmentList);
comboBox.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
commitEdit(newValue);
}
});
comboBox.setOnShown(new EventHandler<Event>() {
@Override
public void handle(Event event) {
getTableView().edit(getIndex(), getTableColumn());
getTableView().getSelectionModel().select(getIndex());
}
});
comboBox.setValue(item);
setGraphic(comboBox);
} else {
setGraphic(null);
}
if (empty) {
setGraphic(null);
}
}
};
return cell;
}
});
当我将状态
状态,我看到 ComboBox
在该特定单元格,但下拉不发生。即使多次点击后,似乎不会在组合框
上执行任何操作。我没有得到任何异常,除了处理一个。其他列可按预期编辑和执行任务。
When I change the status
to the mentioned status, I get the look of ComboBox
in that particular cell but the drop down does not occur. Even after multiple clicks no action seems to be performed on the combobox
. I do not get any exception other than the handled one. Other columns are editable and performing task as expected.
我不知道这里有什么问题。
I have no idea what is wrong here. Can anyone please help me.
推荐答案
因为你总是在(非空)单元格中显示组合框, 't真的需要进入编辑模式作为标准 TextFieldTableCell
等。您的实现更类似于 CheckBoxTableCell
,这本质上绕过了编辑机制。从该课程的文档:
Since you are always displaying the combo box in the (non-empty) cells, you don't really need to go into "editing" mode as the standard TextFieldTableCell
etc does. Your implementation is more similar to the CheckBoxTableCell
, which essentially bypasses the editing mechanism. From the documentation for that class:
所以你的单元实现的行为类似:不调用 edit(...)
(我认为是搞乱了)在 commitEdit(...)
, cancelEdit()
等方法不在编辑状态),但只是直接更新模型类。
So your cell implementation behaves similarly: don't invoke edit(...)
(which I think is messing things up) and don't rely on the commitEdit(...)
, cancelEdit()
etc methods (which won't work as you're not in editing state), but just update the model class directly.
我无法测试,因为没有一个MCVE工作,所以这可能不
I can't test, since there isn't a MCVE to work from, so this might not work directly, but it should be enough to get you started toward something that will work.
targetEnviroment.setCellFactory(new Callback<TableColumn<DevWorkTabBench, String>, TableCell<DevWorkTabBench, String>>() {
@Override
public TableCell<DevWorkTabBench, String> call(TableColumn<DevWorkTabBench, String> param) {
TableCell<DevWorkTabBench, String> cell = new TableCell<DevWorkTabBench, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null) ;
} else {
String status = getTableView().getItems().get(getIndex()).getObjectStatus();
if (status.equalsIgnoreCase("ReadyForDeployment")) {
ComboBox<String> comboBox = new ComboBox(environmentList);
comboBox.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
//commitEdit(newValue);
getTableView().getItems().get(getIndex()).setObjectStatus(newValue);
}
});
comboBox.setValue(item);
setGraphic(comboBox);
} else {
setGraphic(null);
}
}
}
};
return cell;
}
});
这篇关于表单元格组合框 - 未执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!