Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Combobox 未显示javafx组合框上下文菜单_Combobox_Javafx_Contextmenu - Fatal编程技术网

Combobox 未显示javafx组合框上下文菜单

Combobox 未显示javafx组合框上下文菜单,combobox,javafx,contextmenu,Combobox,Javafx,Contextmenu,我的问题是: 我制作了一个组合框,我想在它的元素上使用上下文菜单,所以当我如下图所示设置cellfactory时,我再也看不到其中的项目,上下文菜单也不会显示 CBXGroups.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { public ListCell<String> call(ListView<String> param) {

我的问题是: 我制作了一个组合框,我想在它的元素上使用上下文菜单,所以当我如下图所示设置cellfactory时,我再也看不到其中的项目,上下文菜单也不会显示

CBXGroups.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
    public ListCell<String> call(ListView<String> param) {
    final ListCell<String> cell = new ListCell<String>();
    final ContextMenu cellMenu = new ContextMenu();
    MenuItem rimuoviDalControllo = new MenuItem("RIMUOVI DAL CONTROLLO");
    MenuItem rimuoviDefinitivamente = new MenuItem("RIMUOVI DEFINITIVAMENTE");
    rimuoviDalControllo.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
        Service.deleteGroupFromControl(cell.getText(),CBXControllo.getSelectionModel().getSelectedItem());
        populateLists();
        }
    });
    rimuoviDefinitivamente.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
        Service.deleteGroup(cell.getText());
        populateLists();
        }
    });
    cellMenu.setOnShowing(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent event) {
        cell.requestFocus();
        }
    });
    cellMenu.getItems().addAll(rimuoviDalControllo,rimuoviDefinitivamente);
    cell.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(cell.itemProperty())).then(cellMenu).otherwise((ContextMenu) null));
    return cell;
    }
});
CBXGroups.setCellFactory(新回调(){
公共ListCell调用(ListView参数){
最终ListCell单元格=新ListCell();
最终上下文菜单单元格菜单=新上下文菜单();
MenuItem RIMUOVIDALCONTROLO=新MenuItem(“RIMUOVI DAL CONTROLO”);
MenuItem RIMUOVID定义项=新MenuItem(“RIMUOVI定义项”);
setOnAction(新的EventHandler(){
公共无效句柄(ActionEvent事件){
Service.deleteGroupFromControl(cell.getText(),cbxController.getSelectionModel().getSelectedItem());
大众主义者();
}
});
setOnAction(新的EventHandler()){
公共无效句柄(ActionEvent事件){
Service.deleteGroup(cell.getText());
大众主义者();
}
});
setOnShowing(新的EventHandler(){
公共无效句柄(WindowEvent事件){
cell.requestFocus();
}
});
cellMenu.getItems().addAll(rimuovidealControllo,rimuovidefinitivemente);
cell.contextmenuperty().bind(Bindings.when(Bindings.isNotNull(cell.itemProperty()))。然后(cellMenu)。否则((ContextMenu)null));
返回单元;
}
});

您无法查看项目,因为您尚未在
列表单元格中设置文本。您可以使用一个衬里完成此操作:

cell.textProperty().bind(cell.itemProperty());
上下文菜单比较复杂,我没有一个解决方案。问题是,
组合框
使用显示列表视图,弹出控件的
autoHide
设置为true。因此,当您单击列表视图时,弹出窗口关闭(阻止您看到上下文菜单)。没有办法访问弹出控件,所以我认为没有任何方法可以做到这一点

用组合框中的项目注册上下文菜单似乎是一件不同寻常的事情;我想知道是否有更好的方法来实现你的目标。A在某些方面类似于组合框(显示带有选项的弹出窗口的控件),但它有一个菜单层次结构,因此您可以包括级联菜单。这可能会提供您想要的功能