1

I have a JXTable with custom table model. I added 2 ColorHighlighter's with custom HighlightPredicate's.

Problem is when i click on the column header, the table sorts the rows, BUT the highlighter's remain as for the old view.

How can I update the state of the highlight after sorting a table?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
drzymala
  • 2,009
  • 20
  • 26
  • 1
    have convert view index to model `model int modelRow = convertRowIndexToModel(row)`, maybe works, maybe not depends of SwingX version, – mKorbel Oct 29 '12 at 13:50
  • 1
    there are a few another issues, better could be post an [SSCCE](http://sscce.org/) , short, runnable, compilable, for potentials answerers and future readers too – mKorbel Oct 29 '12 at 13:53
  • Thank you, I will add a simple example later today. – drzymala Oct 29 '12 at 13:56
  • 1
    show the predicate you are using to control the highlighter – kleopatra Oct 29 '12 at 14:25

1 Answers1

0

As @kleopatra mentioned, i looked at my predicate:

    HighlightPredicate spakowany = new HighlightPredicate() {
        @Override
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            TableModel tableModel = table.getModel();
            if (tableModel instanceof StanTableModel) {
                StanTableModel stanTableModel = (StanTableModel) tableModel;
                // int rowIndex = adapter.row;  <-  this was the issue 
                int rowIndex = adapter.convertRowIndexToModel(adapter.row);
                StanTableRow myCustomRow = stanTableModel.getRow(rowIndex);
                if ((myCustomRow.isSpakowany()) {
                    return true;
                }
            }
            return false;
        }
    };

and used @mKorbel idea:

was:

    int rowIndex = adapter.row;

is now:

    int rowIndex = adapter.convertRowIndexToModel(adapter.row);

And it works now.

StanTableModel is my custom table model. It has getRow() function and returns a StanTableRow object which in turn has isSpakowany() function.

drzymala
  • 2,009
  • 20
  • 26
  • 1
    glad you found the problem :-) Consider to change the code snippet with the correctly working line (that is the one with the converted rowIndex), otherwise it's a tad confusing. – kleopatra Oct 29 '12 at 16:36
  • @kleopatra is there another way, meaning `HighlightPredicate` and with `getTableModel`, couldn't be fragile ??? – mKorbel Oct 29 '12 at 18:23