java通过在TableView(JavaFX)中选定的第二行第二列上的ENTER键显示上下文菜单
到目前为止,我只设法使contextMenu出现在
TableView一旦我用这个代码按下回车按钮contextMenu.show(tableView, Side.RIGHT, 0, 0);
。但这样,contextmenu只能在静态位置弹出
一,。如何获取所选第2行第2列的x y位置
我希望contextmenu动态显示,即每当用户在选定行上按ENTER键时,contextmenu将显示在其第2列的选定行中:请查看下面的给定图片
有这样的东西吗
contextMenu.show(tableView, x-SelectedRow2ndCol, y-SelectedRow2ndCol);
二,。Howto Contextmenu完全显示在可见区域中
例如,如果选定的行是TableView的最后一行,因此其位置位于屏幕的最低部分,则contextmenu仍将弹出最后一行上方的所有项目
# 1 楼答案
lookupAll
可用于从TableView
获取所有TableRow
。找到所选的一个,并获取子TableCell
,其中tableColumn
与列匹配。这就得到了TableCell
。使用^{ContextMenu
。这还负责将菜单保持在屏幕上从javadoc:
TableView
上的键侦听器示例:请注意,如果没有可见的选定表行,则此操作不起作用