Skip to main content



      Home
Home » Eclipse Projects » NatTable » How to configure the Selection Style to not override the text foreground color of a selected cell(Selection Handling)
How to configure the Selection Style to not override the text foreground color of a selected cell [message #1799155] Fri, 30 November 2018 10:17 Go to next message
Eclipse UserFriend
Like shown in example _423_ThemeStylingExample in the case of using the ModernNatTableThemeConfiguration during selection the cell foreground color is changed to white. I my use case I want to leave the foreground color unchanged or at least try to mix the colors.

Unfortunately I didn't manage to configure NatTable in the wanted way via using a modified DefaultSelectionStyleConfiguration and/or via a theme modification. Any comments you have would be appreciated.
Re: How to configure the Selection Style to not override the text foreground color of a selected cel [message #1799181 is a reply to message #1799155] Sat, 01 December 2018 02:01 Go to previous messageGo to next message
Eclipse UserFriend
Without showing what you have tried it is hard to say. Typically people forget to update the style also for the selection anchor.
Re: How to configure the Selection Style to not override the text foreground color of a selected cel [message #1799295 is a reply to message #1799181] Tue, 04 December 2018 05:49 Go to previous messageGo to next message
Eclipse UserFriend
Thank you for pointing to a typical problem. My first mistake was that I forgot to configure the cell foreground color for the DisplayMode.SELECT mode:
                Style style = new Style();
                style.setAttributeValue(
                    CellStyleAttributes.FOREGROUND_COLOR,
                   MYCOLOR);           
                configRegistry.registerConfigAttribute(
                    CellConfigAttributes.CELL_STYLE,
                    style,
                    DisplayMode.NORMAL,
                   MYLABEL);
                configRegistry.registerConfigAttribute(
                    CellConfigAttributes.CELL_STYLE,
                    style,
                    DisplayMode.SELECT,
                     MYLABEL);


Actually the selection anchor overrides the cell foreground color and uses always a white color (instead of the configured MYCOLOR color).

I tried to set a painter in the theme but I didn't succeed. Here's the snippet of what I have tried out:
  this.selectionAnchorCellPainter =
            new BackgroundPainter(
                new PaddingDecorator(
                    new TextPainter(false, false),
                    1,
                    5,
                    0,
                    5,
                    false));   
Re: How to configure the Selection Style to not override the text foreground color of a selected cel [message #1799298 is a reply to message #1799295] Tue, 04 December 2018 07:12 Go to previous messageGo to next message
Eclipse UserFriend
It is not the painter you need to adjust, it is the selection anchor style you want to change. This is done via DisplayMode.SELECT and label SelectionStyleLabels.SELECTION_ANCHOR_STYLE

But I am not sure if that will happen if you apply a special foreground color based on a label then. If you specify a foreground color for a label, the configuration of the top label wins. If you want to achieve that every state for every label derives the foreground color, you should only specify the foreground color in the base style configuration (DisplayMode.NORMAL or none with means the same) and do NOT specify a value for the foreground color in the other configurations. The CellStyleProxy will then retrieve the style attribute by inspecting the style hierarchy until the bottom which means the default style.

That said, I assume by removing the foreground color attribute from all other cell style configurations, you should achieve the expected behavior. At least if I have not forgot anything special.
Re: How to configure the Selection Style to not override the text foreground color of a selected cel [message #1799315 is a reply to message #1799298] Tue, 04 December 2018 10:41 Go to previous message
Eclipse UserFriend
The hint was very helpful. In my case I had set a modified DefaultSelectionLayerConfiguration on the SelectionLayer and an extended ModernNatTableThemeConfiguration, which overrides the style configuration.
Previous Topic:NatTable Tree Filtering
Next Topic:How to configure the DefaultSelectionLayerConfiguration
Goto Forum:
  


Current Time: Mon May 19 11:02:07 EDT 2025

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

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

Back to the top