- To achieve the requested styling in NatTable, a combination of styles and painters must be utilized, as detailed in [1]. For more guidance on configuring NatTable and getting started with it, refer to our Getting Started Tutorial [2]
- In order to create a layout similar to what was asked for, you will need to register a combination of
ICellPainter
.
- If you wish to add padding (not margin) between the cell border and its content, utilize the
PaddingDecorator
.
- For combining an image with text, employ a
CellPainterDecorator
that includes a base painter for the text and uses an additional ImagePainter
.
- The ability to render text with various fonts is exclusive to the
RichTextCellPainter
within the NatTable Nebula Extension, requiring Java 1.7.
- CSS styling in NatTable involves creating a styling configuration through CSS, without any further assistance. The support for CSS can be found in the NatTable E4 Extension, which demands Java 1.8. More details are available in the 1.4 New & Noteworthy page [3]
So the answer to a) is: NatTable Core does not support rendering text with two different fonts, hence a custom ICellPainter
implementation is necessary to achieve this.
Regarding b), a complex painter should be created and registered as follows:
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new BackgroundPainter(
new PaddingDecorator(
new CellPainterDecorator(
new PaddingDecorator(new RichTextCellPainter(), 10, 0, 0, 0),
CellEdgeEnum.LEFT,
new ImagePainter()),
2, 5, 2, 5)),
DisplayMode.NORMAL,
ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 0);
This example assumes that column labels have been applied using the ColumnLabelAccumulator
, and the painter configuration is specifically for the first column. Additionally, ensure that the CellStyleAttributes.IMAGE
attribute is set for the respective cell to be rendered by the ImagePainter
. If the image is fixed, it should be provided as a constructor parameter.
As for the content, it must include the necessary HTML markup for displaying different fonts, like so:
<p><strong><span style="font-size:14px">This is a test</span></strong></p>
<p><span style="color:rgb(128, 128, 128)"><span style="font-size:12px">This is a test</span></span></p>
For c), achieving the complex painter structure shown earlier is not feasible with CSS due to limitations such as configuring multiple paddings, which is unsupported in NatTable CSS. Moreover, the RichTextPainter is not native to the E4 Extension and has to be manually registered to the CellPainterFactory
like below:
CellPainterFactory.getInstance().registerContentPainter(
"richtext",
(painterProperties, underlying) -> {
return new RichTextCellPainter();
});
Additional considerations need to be made for handling extra attributes along with this registration.
Thus, the CSS implementation would resemble something as shown below:
painter: background padding decorator richtext;
decoration: left url('./nebula_logo_16.png') 5 true;
padding: 2 5;
[1]
[2]
[3]