java - Table.getItem 仅在 RHEL6 中返回错误的项目

标签 java swt rhel6

我有一个奇怪的问题,

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

  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 库。

最佳答案

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

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

<小时/>

快速而肮脏的解决方案是计算 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,您可以让编辑器了解其正在表中编辑的项目。

关于java - Table.getItem 仅在 RHEL6 中返回错误的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28528417/

相关文章:

java - 无法从 Servlet 检索数据

java - Java 中不分配返回值的非 void 方法调用

java - 抽象类中的私有(private)引用

java - SWT Splitpane 可滚动

linux - LVM , 导致服务器不再启动 :(

java - Spring Data JPA 删除不是我所期望的

java - Eclipse 插件 - 弹出菜单扩展

Java Swt Text(SWT.MULTI)附加文本而不滚动

linux - 是否可以在 Linux 中设置 2 JAVA_HOME?

compiler-errors - gcc 汇编程序消息无法打开/tmp/ccqjY5HV.s 以读取没有这样的文件或目录