SwingX JXTable: use ColorHighlighter to color rows based on a “row object”

后端 未结 1 1484
孤城傲影
孤城傲影 2021-01-13 03:22

I\'m using JXTable and I know how to do this based on DefaultRenderers for JTable, but I want to know how to do it in a way that\'s JXTable-friendly based on HighlighterPipe

相关标签:
1条回答
  • 2021-01-13 03:39

    never mind, I figured it out. It was just hard to figure out the way to use ComponentAdapter propertly.

    JXTable table = ...
    final List<Item> itemList = ...
    
    final HighlightPredicate myPredicate = new HighlightPredicate() {
          @Override 
          public boolean isHighlighted(
                Component renderer, 
                ComponentAdapter adapter) {
    
                Item item = itemList.get(adapter.row);
                return testItem(item);
          }
    
          public boolean testItem(Item item) { ... }
    }
    
    ColorHighlighter highlighter = new ColorHighlighter(
          myPredicate,
          Color.RED,   // background color
          null);       // no change in foreground color
    
    table.addHighlighter(highlighter);
    
    0 讨论(0)
提交回复
热议问题