【问题标题】:NatTable - CheckBoxCellEditor & CheckBoxPainter displaying the text on single clickNatTable - CheckBoxCellEditor 和 CheckBoxPainter 在单击时显示文本
【发布时间】:2017-09-25 23:25:28
【问题描述】:

我正在使用 CheckBoxCellEditor 和 CheckBoxPainter 在 NatTable 中显示布尔属性,如下所示

问题:使用鼠标单击单元格时,它将布尔值显示为如下所示的文本,而不是将状态重置为 false。

下面是我的代码sn-p,

//register the column
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(
                bodyLayer.getBodyDataLayer());
        bodyLayer.getBodyDataLayer().setConfigLabelAccumulator(columnLabelAccumulator);
        columnLabelAccumulator.registerColumnOverrides(0, COLUMN_BOOKMARK_LABEL);

//added the CheckBoxCellEditor and CheckBoxCellPainter to configuration.
     natTable.addConfiguration(new AbstractRegistryConfiguration() {
                    @Override
                    public void configureRegistry(IConfigRegistry configRegistry) {
                        configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.NORMAL,
                                COLUMN_BOOKMARK_LABEL);

                        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(ImageUtil.getImage("Images.BookmarkChecked"),
                                ImageUtil.getImage("Images.BookmarkUnchecked")),
                                DisplayMode.NORMAL, COLUMN_BOOKMARK_LABEL);

                        configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER,
                                new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, COLUMN_BOOKMARK_LABEL);
                    }
                });

我也让 rowselectionProvider 将默认选择设置为第一行,并根据行选择刷新属性 UI。

关于缺少链接的任何指针。TIA

【问题讨论】:

    标签: java eclipse checkbox swt nattable


    【解决方案1】:

    看起来有一个为DisplayMode.SELECT 注册的画家,而不是在DisplayMode.NORMAL 中为您的标签注册的画家。添加此行应该可以解决您的问题

    configRegistry.registerConfigAttribute(
        CellConfigAttributes.CELL_PAINTER, 
        new CheckBoxPainter(
            ImageUtil.getImage("Images.BookmarkChecked"),
            ImageUtil.getImage("Images.BookmarkUnchecked")),
        DisplayMode.SELECT, 
        COLUMN_BOOKMARK_LABEL);
    

    我不确定您的其余样式配置。通常,配置是分层的。所以需要详细检查为什么使用另一个画家而不是NORMAL模式。

    【讨论】:

    • 非常感谢您的快速回复。你是对的,我有自定义 HeaderStyleConfiguration 它覆盖了 CheckBoxPainter 模式。我重新排序了配置,现在,我可以看到处于选中和未选中状态的图像。
    • 现在鼠标事件监听器不会触发选择。 addConfiguration( new AbstractUiBindingConfiguration() { public void configureUiBindings( UiBindingRegistry uiBindingRegistry iBindingRegistry.registerFirstDoubleClickBinding( new CellEditorMouseEventMatcher( GridRegion.BODY ), new MouseEditAction() );}
    • 您能接受这个答案吗?所以有类似问题的用户更容易找到解决方案。
    • 您是否使用自定义编辑绑定配置?然后你需要确保 CheckboxPainter 配置正确。 uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class), new MouseEditAction());或者使用 DefaultEditBindings 配置。
    • 即使使用 DefaultBindingConfiguration,鼠标选择也不起作用。配置的层次顺序对编辑也很重要吗?
    猜你喜欢
    • 2014-06-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 2017-06-08
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    相关资源
    最近更新 更多