从代码请求开始编辑TreeTableCell(Start editing a TreeTableCell from a code request)

编程入门 行业动态 更新时间:2024-10-10 15:25:03
从代码请求开始编辑TreeTableCell(Start editing a TreeTableCell from a code request)

我有一个很好的TreeTableView。 我已经实现了单击“TreeTableCell”时出现的上下文菜单。 在我的上下文菜单中,我有一个名为“edit”的MenuItem,当选中时,我想让当前的TreeTableCell开始编辑。 不幸的是,我无法弄清楚如何正确地开始编辑单元格。

我最初的想法是,由于上下文菜单回调在我的TreeTableCell实例的范围内,我将调用我的单元格的“startEdit”方法。 这似乎有效...但是,当commitEdit发生时,我在JavaFX的内部深处得到一个NullPointerException。 这让我觉得显式调用startEdit()是错误的想法,并且应该有一种正确的方法可以使表中的特定单元格开始编辑循环。

I have a TreeTableView that is working great. I have implemented a context menu that appears when the "TreeTableCell" is clicked. In my context menu, I have a MenuItem called "edit" that, when selected, I want to cause the current TreeTableCell to start editing. Unfortunately, I am unable to figure out how to correctly start editing the cell.

My initial thinking was that since the context menu callback is in the scope of my TreeTableCell instance, I would call the "startEdit" method of my cell. This appears to work ... however, when the commitEdit occurs, I get a NullPointerException deep within the internals of JavaFX. This makes me think that explicitly calling startEdit() is the wrong thinking and that there should be a correct way to cause a specific cell in the table to begin its edit cycle.

最满意答案

在较低级别的学习之后,我能够找到答案。 我假设我可以对我的TreeTableCell调用startEdit() ,但这不是标记表格单元格的正确方法,因为输入是编辑模式。

相反,TableView和TreeTableView都公开了一个带有两个参数的edit()方法:

表的行号从0开始索引 表的TableColumn

行和列的组合提供表格中单元格的唯一位置。 调用edit()会将单元格置于编辑模式。

这是用于TableView编辑方法的JavaDoc:

用于TableView的JavaDoc编辑

I was able to find the answer after lower level study. I had assumed that I could call startEdit() against my TreeTableCell however that is not the correct way to flag a table cell as entering is editing mode.

Instead both TableView and TreeTableView expose an edit() method that take two parameters:

The row number of the table indexed from 0 The TableColumn of the table

The combination of row and column provide a unique location of a cell in the table. Calling edit() places the cell in editing mode.

Here is the JavaDoc for TableView edit method:

JavaDoc for TableView edit

更多推荐

本文发布于:2023-08-04 17:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1419185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑   代码   TreeTableCell   Start   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!