gpt4 book ai didi

java - 如何为 nattable 中的某些列设置自定义样式?

转载 作者:行者123 更新时间:2023-12-02 04:55:37 25 4
gpt4 key购买 nike

我需要为 nattable 中的某些列而不是所有列设置自定义样式。我无法设置这样的配置:

natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

因为这会将配置设置为整个表。我必须仅覆盖特定列的配置。在我的例子中,列应该具有如下水平对齐设置:

setHAlign(HorizontalAlignmentEnum.RIGHT);

我怎样才能实现这个目标?谢谢!

最佳答案

来自NatTable styling docs

To enable conditional styling, the custom style needs to be registered in the IConfigRegistry against the label defined before.

Style style = new Style();
// You can set other attributes here
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_RED);

configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, // attribute to apply
style, // value of the attribute
DisplayMode.NORMAL, // apply during normal rendering
CELL_LABEL);

// apply for all cells with this label

要将 CELL_LABEL 标签应用到您的色谱柱,请按照 NatTable configuration docs 中的说明进行操作。

Attaching a label to a cell

Following the overall design convention, Layers can add labels to cells. In order to attach a label to a cell(s) you need to implement the IConfigLabelAccumulator interface. The IConfigLabelAccumulator.accumulateConfigLabels() is called on each layer. Every layer can add its labels to the LabelStack.

The most common use cases are available out of the box, including but not limited to:

CellOverrideLabelAccumulator - applies labels to cell(s) containing a specified data value ColumnOverrideLabelAccumulator - applies labels to all cells in a column You can make custom implementations for your own rules

关于java - 如何为 nattable 中的某些列设置自定义样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28799492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com