0

I have a set of rows with some interesting data. I need to point user on them.

1. So I can save row numbers and highlight them with the help of highlighter. But when I expand/collapse tree, row numbers are changed and highlighting is shifted of these rows to another, uninteresting one;
2. I may use multiple selection to select all these rows and then prevent selection (intercept the selection event) to unable the selection reset. But it is bad idea to prevent selection..;
3. To solve the problem of the first variant, it is possible to try to track the number of expanded/collapsed items. But in this case I was stopped with the case when we collapse a multi-layer expanded sub-tree. I do not know how to find how many rows are really removed;
4. I do not want to traverse all the tree and check on data values.

I need to somehow realize the same mechanism that is used for selection: we collapse/expand rows but selection is fixed. But I do not know how to do it.

Shubham Kharde
  • 228
  • 2
  • 10
DrDecay
  • 59
  • 1
  • 10

1 Answers1

0

As mentioned in this question, when creating the HighlightPredicate, there is no need to focus on the row's index. Just check for the value(s), that might be interesting.

final JXTreeTable treeTable = new JXTreeTable();
final int interestingColumn = 3;
final Color interestingCellBackgroundColor = Color.GREEN;
final Color interestingCellForegroundColor = Color.BLACK;
treeTable.addHighlighter(new ColorHighlighter(new HighlightPredicate() {
        public boolean isHighlighted(Component rend, ComponentAdapter adapt) {
            Object value = adapt.getValue(interestingColumn);
            return isValueInteresting(value));
        }
    }, interestingCellBackgroundColor, interestingCellForegroundColor));
Community
  • 1
  • 1
Carsten
  • 2,047
  • 1
  • 21
  • 46