【问题标题】:How to gray selection highlight when NatTable not in focus当 NatTable 不在焦点时如何灰色选择突出显示
【发布时间】:2019-04-24 20:35:58
【问题描述】:

某些列表和表格在失去键盘焦点时会使其选择变灰。

在存在多个列表/表格的情况下,这有助于向用户传达哪些选择处于活动状态。

有没有简单的方法用 NatTable 做到这一点?

到目前为止,我想出的最好方法是在 DisplayMode.SELECT 的不同属性之间切换,因为焦点来来去去——但我不确定在调用 NatTable.configure() 之后我能做到这一点。

【问题讨论】:

    标签: eclipse-rcp nattable


    【解决方案1】:

    是的,您可以在调用NatTable#configure() 后动态更改配置属性。这是动态变化的常用方法。另一种方法是为特殊标签配置选择样式,并仅在表处于活动状态时应用该标签。在这个例子中可以看到这种方法。

    https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_505_Selection/_5054_SelectionProviderExample.java

    【讨论】:

      【解决方案2】:

      在@DirkFauth 的回答之后,我有这个工作。这个答案包括一些细节。

      表配置好NatTable.configure()后,你可以不用NatTable.addConfiguration(IConfiguration)修改配置,而是调用IConfiguration.configureRegistry(IConfigRegistry)。例如:

        myConfiguration.configureRegistry( myTable.getConfigRegistry() )
      

      在 configureRegistry() 的实现中,您可以设置选定单元格和锚定单元格的样式:

          configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE,
                selectedStyle, DisplayMode.SELECT, GridRegion.BODY);
      
          configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE,
                anchorStyle, DisplayMode.SELECT,
                SelectionStyleLabels.SELECTION_ANCHOR_STYLE);
      

      当表处于非活动状态时,selectedStyleanchorStyle 可以修改为它们通常设置的克隆。例如:

      private static Color myInactiveColor = ...;
      
      public static Style makeInactiveBodyCellStyleFrom(@Nonnull Style style) {
          Style rv = style.clone();
      
          rv.setAttributeValue( CellStyleAttributes.BACKGROUND_COLOR,
              myInactiveColor );
      
          return rv;
      }
      

      可以对选定的行和列标题的样式进行类似的工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-07
        • 1970-01-01
        • 2011-02-24
        • 2015-04-05
        • 1970-01-01
        • 2014-10-06
        • 2014-09-16
        相关资源
        最近更新 更多