我有以下控制器在我的gui上多次实例化。原因是因为它有一个填充了不同类型数据的tableview。看起来像这样
class Controller {
@FXML
TableView<Map<String, String> myTable;
private Manager manager;
//Each TableView has different ammount of columns with different names that get dynamically added to the table view using this function
public void setUpColumns(List<TableColumn<Map<String, String>, String>> columns){
myTable.getColumns().addAll(columns);
addContextMenuToColumnHeaders();
}
private addContextMenuToColumnHeaders(){
for (TableColumn<Map<String, String>, ?> tc : myTable.getColumns()){
ContextMenu addToGraphContextMenu = createAddToGraphContextMenu(tc);
tc.setContextMenu(addToGraphContextMenu);
}
}
private ContextMenu createAddToGraphContextMenu(TableColumn<Map<String, String> String> tc){
for (MangerHandledObject mHO : manager.getHandledObjects()){
MenuItem menuItem = new MenuItem(mHO.getName());
menuItem.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event){
//I want each menu item to have access to the column that is added to get the name of the column. Even after dynamically adding new menuItems
manager.callMethod(tc.getName());
}
});
}
}
}
经理处理的对象不是静态的。因此,从经理保留的列表中添加和删除。我试过这个
contextMenu.setOnShowing(......)
在显示之前,它将始终从经理检查列表并重新制作上下文菜单项。但问题是,当执行此操作时,我无法访问列。有没有办法绕过这个?我应该实现自己的上下文菜单,以获得列名称的字段吗?
答案 0 :(得分:0)
有效。但是我必须在我的上下文菜单中添加至少一个虚拟MenuItem才能显示它。