Skip to main content



      Home
Home » Eclipse Projects » NatTable » natTable Focus(natTable selection)
natTable Focus [message #1847815] Tue, 09 November 2021 02:43 Go to next message
Eclipse UserFriend
Hi all,
requirement : change the selected row color " blue to gray " if nat table is not in focus .
is there any example available in nat table for this kind of implementation ?

or is there any API by nat table that give me the selection/focus status of nat table ?


thanks
Re: natTable Focus [message #1847819 is a reply to message #1847815] Tue, 09 November 2021 04:05 Go to previous message
Eclipse UserFriend
NatTable is a SWT widget. So of course you can check the focus state as with any other SWT widget. For the selection state you need access to the SelectionLayer.

If you want to change the styling when the focus on the NatTable changes, simply implement and register a FocusListener that dynamically changes the styling directly in the ConfigRegistry:

natTable.addFocusListener(new FocusListener() {

    @Override
    public void focusLost(FocusEvent e) {
        Style style = new Style();
        style.setAttributeValue(
                CellStyleAttributes.BACKGROUND_COLOR,
                GUIHelper.COLOR_GRAY);
        natTable.getConfigRegistry().registerConfigAttribute(
                CellConfigAttributes.CELL_STYLE,
                style,
                DisplayMode.SELECT);
    }

    @Override
    public void focusGained(FocusEvent e) {
        Style style = new Style();
        style.setAttributeValue(
                CellStyleAttributes.BACKGROUND_COLOR,
                GUIHelper.COLOR_BLUE);
        natTable.getConfigRegistry().registerConfigAttribute(
                CellConfigAttributes.CELL_STYLE,
                style,
                DisplayMode.SELECT);
    }
});


Have in mind that the selection anchor is styled differently.
Previous Topic:dynamic coloring of cells using CellOverrideLabelAccumulator with filtering/grouping/sorting
Next Topic:How we can apply filter by color on Nattable like we did in excel?
Goto Forum:
  


Current Time: Fri May 23 14:51:04 EDT 2025

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

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

Back to the top