0

我已经尝试过:在配置注册表中设置主题配置和使用边框样式注册样式。但我没有看到边界。还有什么我想念的吗?

在我的 postConstruct 方法中,我初始化 NatTable 如下:

    final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration(imageRightUp, imageTreeRightDown);

    TextPainter textPainter = new TextPainter(true, false);
    ImagePainter imagePainter = new ImagePainter(threeDots);
    CellPainterDecorator cellPainterDecorator = new CellPainterDecorator(textPainter, CellEdgeEnum.RIGHT, imagePainter);

    configRegistry.registerConfigAttribute(
            CellConfigAttributes.CELL_PAINTER,
            cellPainterDecorator,
            DisplayMode.NORMAL,
            LABEL_1);

    Style style = new Style();

    style.setAttributeValue(
            CellStyleAttributes.BACKGROUND_COLOR,
            GUIHelper.getColor(44, 104, 125));
    style.setAttributeValue(
            CellStyleAttributes.FOREGROUND_COLOR,
            GUIHelper.COLOR_WHITE);
    style.setAttributeValue(
            CellStyleAttributes.BORDER_STYLE,
            new BorderStyle(5, GUIHelper.COLOR_BLACK, LineStyleEnum.SOLID));

    configRegistry.registerConfigAttribute(
            // attribute to apply
            CellConfigAttributes.CELL_STYLE,
            // value of the attribute
            style,
            // apply during normal rendering i.e not
            // during selection or edit
            DisplayMode.NORMAL,
            // apply the above for all cells with this label
           LABEL_1);

    configRegistry.registerConfigAttribute(
            // attribute to apply
            CellConfigAttributes.CELL_STYLE,
            // value of the attribute
            style,
            // apply during normal rendering i.e not
            // during selection or edit
            DisplayMode.NORMAL,
            // apply the above for all cells with this label
            LABEL_2);

    NatTable natTable = new NatTable(parent, viewportLayer, false);
    GridData d = new GridData(SWT.FILL, SWT.FILL, true, true, 1,1);
    natTable.setLayoutData(d);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultTreeLayerConfiguration(treeLayer));
    natTable.setTheme(modernTheme);
    natTable.configure();

这也是主题配置:

public class ModernNatTableThemeConfiguration extends DefaultNatTableThemeConfiguration {


    public ModernNatTableThemeConfiguration( Image imageRightUp, Image imageTreeRightDown ){

        TreeImagePainter treeImagePainter = new TreeImagePainter(
                false,
                imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
        this.treeStructurePainter = new BackgroundPainter(new PaddingDecorator(
                new IndentedTreeImagePainter(10, null, CellEdgeEnum.LEFT,
                        treeImagePainter, false, 2, true), 0, 5, 0, 5, false));

       TreeImagePainter treeSelectionImagePainter = new TreeImagePainter(
                false,
                imageRightUp, imageTreeRightDown, null); //$NON-NLS-1$//$NON-NLS-2$
        this.treeStructureSelectionPainter = new BackgroundPainter(
                new PaddingDecorator(new IndentedTreeImagePainter(10, null,
                        CellEdgeEnum.LEFT, treeSelectionImagePainter, false, 2,
                        true), 0, 5, 0, 5, false));

        this.treeBgColor = GUIHelper.getColor(44, 104, 125);
        this.treeFgColor = GUIHelper.getColor(44, 104, 125);
    }
 }
4

1 回答 1

0

我认为我们需要明确条款。是否要删除边框或网格线?因为您在样式配置中指定了边框,所以边框应该在那里。

如果你想摆脱网格线,你需要配置CellLayerPainter.

例如,可以这样做:

configRegistry.registerConfigAttribute(
            CellConfigAttributes.RENDER_GRID_LINES, 
            Boolean.FALSE);

顺便说一句,直接修改ConfigRegistry您在代码中所做的事情并不是一个好习惯。您应该创建一个IConfiguration(例如AbstractRegistryConfiguration)并将其注册IConfiguration到您的 NatTable 实例。否则NatTable#configure()可能会在配置时覆盖您的更改。

这在这里解释:http ://www.vogella.com/tutorials/NatTable/article.html#architecture_configuration

于 2015-10-15T06:52:10.523 回答