Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java CheckboxCellEditor显示文本而不是复选框_Java_Eclipse_Swt_Rcp - Fatal编程技术网

Java CheckboxCellEditor显示文本而不是复选框

Java CheckboxCellEditor显示文本而不是复选框,java,eclipse,swt,rcp,Java,Eclipse,Swt,Rcp,我正在使用下面的 org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent) CellEditor[] editors = new CellEditor[columnNames.length]; editors[7] = new CheckboxCellEditor(table); public Object getValue(Object element, String property

我正在使用下面的

org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent)
CellEditor[] editors = new CellEditor[columnNames.length];
editors[7] = new CheckboxCellEditor(table);
public Object getValue(Object element, String property) {
        Object result = null;
        ...
        result = Boolean.valueOf(task.isDfRequested());
        return result;
}

 public void modify(Object element, String property, Object value) {
       item.isSelected(((Boolean)value).booleanValue());
}
 public String getColumnText(Object element, int columnIndex) {
        String result = "";
        try { 
            result = Boolean.toString(item.isSelected());
        } catch (Exception ex) { } 

        break;
我正在使用CellEditor创建一个表查看器,并执行以下操作

org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent)
CellEditor[] editors = new CellEditor[columnNames.length];
editors[7] = new CheckboxCellEditor(table);
public Object getValue(Object element, String property) {
        Object result = null;
        ...
        result = Boolean.valueOf(task.isDfRequested());
        return result;
}

 public void modify(Object element, String property, Object value) {
       item.isSelected(((Boolean)value).booleanValue());
}
 public String getColumnText(Object element, int columnIndex) {
        String result = "";
        try { 
            result = Boolean.toString(item.isSelected());
        } catch (Exception ex) { } 

        break;
我有一个CellModifier,它有以下内容

org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent)
CellEditor[] editors = new CellEditor[columnNames.length];
editors[7] = new CheckboxCellEditor(table);
public Object getValue(Object element, String property) {
        Object result = null;
        ...
        result = Boolean.valueOf(task.isDfRequested());
        return result;
}

 public void modify(Object element, String property, Object value) {
       item.isSelected(((Boolean)value).booleanValue());
}
 public String getColumnText(Object element, int columnIndex) {
        String result = "";
        try { 
            result = Boolean.toString(item.isSelected());
        } catch (Exception ex) { } 

        break;
最后,我有一个LabelProvider,它具有以下内容

org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent)
CellEditor[] editors = new CellEditor[columnNames.length];
editors[7] = new CheckboxCellEditor(table);
public Object getValue(Object element, String property) {
        Object result = null;
        ...
        result = Boolean.valueOf(task.isDfRequested());
        return result;
}

 public void modify(Object element, String property, Object value) {
       item.isSelected(((Boolean)value).booleanValue());
}
 public String getColumnText(Object element, int columnIndex) {
        String result = "";
        try { 
            result = Boolean.toString(item.isSelected());
        } catch (Exception ex) { } 

        break;

但是,在我的UI中,我没有复选框,而是选择了true或false&单击它会将状态切换为false或true。关于为什么我没有复选框有什么想法吗?

好吧,我不知道SWT是如何工作的,也不知道你们在谈论什么组件

但我知道,当使用Swing时,您可以为JTable中的列使用自定义编辑器。如果不告诉表该列的数据类,则会调用该数据的toString()方法。但是,如果您告诉表格布尔数据显示在列中,则表格将使用复选框编辑器


听起来像是一个类似的症状,但我不知道你的具体解决方案。

我决定只实施一个别人一直在使用的肮脏黑客

创建复选框的两个图像,一个选中,另一个未选中。根据布尔值在两者之间切换状态


它并不完美,但现在它完成了任务

我在
CheckboxCellEditor
类的源代码中搜索过,在构造函数中,与CellEditor关联的控件是在
createControl(复合父项)
方法中创建的。此方法在
CellEditor
类中是抽象的,在
CheckboxCellEditor
中实现如下:

protected Control createControl(Composite parent) {
    return null;
}
因此没有创建控件,这就是为什么没有看到复选框。在该类的文档中,您可以阅读:

请注意,此实现非常简单 伪造它,不会产生任何错误 新的控制。仅仅激活 此编辑器意味着 该复选框正在由 最终用户;侦听器方法 立即调用applyEditorValue 发出改变的信号

我使用带有yes和no项的ComboBoxCellEditor解决了这个问题

问候。

他们在这里也这么做:当我第一次看到他们的源代码时,我也不明白为什么他们在CheckboxCellEditor中使用了两个图像。同时,他们使用ComboBoxCellEditor,它不使用任何图像。它显示一个组合框。所以我不清楚为什么CheckboxCellEditor不返回复选框。