0

我有一个奇怪的问题,

我有一个包含 2 列和 3 行的表格,每个单元格文本可以在运行时进行编辑,当我编辑第三行第二列中的单元格时,我也使用相同的文本修改了上部单元格,这仅发生在 redhat6 上。可与 TextCellEditor 类型的 rhe5 和 rhe4 编辑器配合使用;

  TableItem item = table.getItem(textEditor.getControl().getLocation());

Table.class 中的 getItem 方法实现是:

public TableItem getItem (Point point) {
    checkWidget();
    if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
     int /*long*/ [] path = new int /*long*/ [1];
    OS.gtk_widget_realize (handle);
     if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path,null, null, null)) return null;
    if (path [0] == 0) return null;
    int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]);
    TableItem item = null;
    if (indices != 0) {
        int [] index = new int [1];
        OS.memmove (index, indices, 4);
        item = _getItem (index [0]);
    }
    OS.gtk_tree_path_free (path [0]);
    return item;
}

我想这可能是我的 GTK 库。我安装了 GTK2 库。

4

1 回答 1

1

我认为触发此错误是因为字段Text内部TextEditorField有一些边距或最小尺寸不适合单元格,或者行高计算不正确。

但是,我建议您不要尝试使用 查找文本编辑器指向的表格项getItem(Point),因为可能还有其他类型的问题,并且这种行为通常无法保证。我想说这应该主要用于查找“被鼠标指向的一项”。就像这里的这个问题一样。实际上,您可以算自己很幸运,您实际上发现了这个错误。


快速而肮脏的解决方案是计算 的中心Text.getBounds()并使用它来查找项目,即:

Rectangle bounds = textEditor.getControl().getBounds();
Point location = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
table.getItem(location);

但更好的选择是,如果您运行的是 SWT >= 3.3,则使用为每列TableViewerColumn.setEditingSupport(EditingSupport)设置EditingSupport,因为EditingSupport您可以使编辑器了解它正在表中编辑的项目。

于 2015-02-17T17:39:40.877 回答