Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » coloring of nattable cells dynamically (coloring of nattable cells dynamically with row and column index during runtime)
coloring of nattable cells dynamically [message #1843949] Wed, 25 August 2021 13:30 Go to next message
Vinod Gangal is currently offline Vinod GangalFriend
Messages: 4
Registered: August 2021
Junior Member
I have a nattable inwhich i want to color some of the cells based on some actions that are performed by the user.

I understand that we can color the cells of nattable using the cellLabelAccumulator. But this is only useful when we know which cells to be colored before hand.

In my case, i need to color the nattable dynamically after the nattable is rendered.
Is there any way i can color the nattable during runtime i.e after the nattable has been rendered on the editor?

I tried to add the labels to the cellLabelAcumulator using the following code snippet to dynamically color the nattable cells but the cells are not colored.

getBodyLayerStack().getConfigLabelsByPosition(0,0).addLabelOnTop("FOO_LABEL");

Any idea how i could achieve this?

[Updated on: Wed, 25 August 2021 16:56]

Report message to a moderator

Re: coloring of nattable cells dynamically [message #1843955 is a reply to message #1843949] Wed, 25 August 2021 14:22 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
The labels are calculated on every paint process. So adding a label from the outside won't work.

To solve your requirement you need to implement a a mechanism that stores a label on some action. This can for example be achieved using the CellOverrideLabelAccumulator as shown in this example

https://git.eclipse.org/c/nattable/org.eclipse.nebula.widgets.nattable.git/tree/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_102_Configuration/Applying_style_to_a_cell.java

Re: coloring of nattable cells dynamically [message #1843966 is a reply to message #1843955] Wed, 25 August 2021 16:54 Go to previous messageGo to next message
Vinod Gangal is currently offline Vinod GangalFriend
Messages: 4
Registered: August 2021
Junior Member
Hi Dirk,

Thank you for the response.
From the Example i see that it applies the label to all cells matching a particular value in a specified column hence all matching values are colored.

My requirement is to color only a specific cell. I get the cells row and column index dynamically after some user action and i want to color only that particular cell identified by its row and column index.
Any Idea if CellOverrideLabelAccumulator can be used to fulfil my requirement?
Re: coloring of nattable cells dynamically [message #1843967 is a reply to message #1843966] Wed, 25 August 2021 17:16 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well you can also have a look at this example

https://git.eclipse.org/c/nattable/org.eclipse.nebula.widgets.nattable.git/tree/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_104_Styling/_000_Styled_grid.java

As I said before, you can always implement your own label accumulator that stores labels internally in some way after a user interaction.
Re: coloring of nattable cells dynamically [message #1843969 is a reply to message #1843967] Wed, 25 August 2021 18:29 Go to previous message
Vinod Gangal is currently offline Vinod GangalFriend
Messages: 4
Registered: August 2021
Junior Member
Hi Dirk,

I implemented my own custom CellOverrideLabelAccumulator to accumulate labels for the row and column indices and it works as expected now :)

Thanks a ton..
Previous Topic:Drag and Drop in a TreeLayer
Next Topic:Closing combo box dropdowns when leaving NatTable editor
Goto Forum:
  


Current Time: Fri Apr 26 09:31:25 GMT 2024

Powered by FUDForum. Page generated in 0.02689 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top