0
我有以下控制器在我的gui上多次實例化。原因是它有一個tableview被填充不同類型的數據。看起來像這樣動態添加上下文菜單項到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(......)
,並顯示它總是從經理檢查列表和之前重新使上下文菜單項。但問題是,執行此操作時,我無法再訪問這些列。有什麼辦法可以繞過這個嗎?我是否應該實現自己的上下文菜單以獲得列名稱的字段?