package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.Objects;
import javax.swing.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private final String[] columnNames = {"String", "Integer", "Boolean"};
    private final Object[][] data = {
        {"aaa", 12, true}, {"bbb", 5, false},
        {"CCC", 92, true}, {"DDD", 0, false}
    };
    private final DefaultTableModel model = new DefaultTableModel(data, columnNames) {
        @Override public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    private final JTable table = new SortingColumnColorTable(model);
    //private final transient RowSorter<? extends TableModel> sorter = new TableRowSorter<>(model);

    private MainPanel() {
        super(new BorderLayout());
        //table.setRowSorter(sorter);
        table.setAutoCreateRowSorter(true);

        add(new JButton(new AbstractAction("clear SortKeys") {
            @Override public void actionPerformed(ActionEvent e) {
                //sorter.setSortKeys(null);
                table.getRowSorter().setSortKeys(null);
            }
        }), BorderLayout.SOUTH);
        add(new JScrollPane(table));
        setPreferredSize(new Dimension(320, 240));
    }

    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class SortingColumnColorTable extends JTable {
    private static final Color EVEN_COLOR = new Color(250, 230, 230);
    public SortingColumnColorTable(TableModel model) {
        super(model);
    }
    @Override public Component prepareRenderer(TableCellRenderer tcr, int row, int column) {
        Component c = super.prepareRenderer(tcr, row, column);
        if (isRowSelected(row)) {
            c.setForeground(getSelectionForeground());
            c.setBackground(getSelectionBackground());
        } else {
            c.setForeground(getForeground());
            c.setBackground(isSortingColumn(column) ? EVEN_COLOR : getBackground());
        }
        return c;
    }
    private boolean isSortingColumn(int column) {
        RowSorter<? extends TableModel> sorter = getRowSorter();
        if (Objects.nonNull(sorter)) {
            List<? extends RowSorter.SortKey> keys = sorter.getSortKeys();
            if (keys.isEmpty()) {
                return false;
            }
            if (column == convertColumnIndexToView(keys.get(0).getColumn())) {
                return true;
            }
        }
        return false;
    }
}

@@ -280,16 +280,86 @@
 Panel %7B%0A
+    private static final Color EVEN_COLOR = new Color(250, 230, 230);%0A
     priv
@@ -425,16 +425,16 @@
 lean%22%7D;%0A
-
     priv
@@ -822,138 +822,953 @@
 new 
-SortingColumnColorTable(model);%0A    //private final transient RowSorter%3C? extends TableModel%3E sorter = new TableRowSorter%3C%3E(model)
+JTable(model) %7B%0A        @Override public Component prepareRenderer(TableCellRenderer tcr, int row, int column) %7B%0A            Component c = super.prepareRenderer(tcr, row, column);%0A            if (isRowSelected(row)) %7B%0A                c.setForeground(getSelectionForeground());%0A                c.setBackground(getSelectionBackground());%0A            %7D else %7B%0A                c.setForeground(getForeground());%0A                c.setBackground(isSortingColumn(column) ? EVEN_COLOR : getBackground());%0A            %7D%0A            return c;%0A        %7D%0A        private boolean isSortingColumn(int column) %7B%0A            RowSorter%3C? extends TableModel%3E sorter = getRowSorter();%0A            if (Objects.nonNull(sorter)) %7B%0A                List%3C? extends RowSorter.SortKey%3E keys = sorter.getSortKeys();%0A                return !keys.isEmpty() && column == convertColumnIndexToView(keys.get(0).getColumn());%0A            %7D%0A            return false;%0A        %7D%0A    %7D
 ;%0A%0A 
@@ -1831,46 +1831,8 @@
 ));%0A
-        //table.setRowSorter(sorter);%0A
     
@@ -2006,52 +2006,8 @@
 ) %7B%0A
-                //sorter.setSortKeys(null);%0A
     
@@ -2959,32 +2959,32 @@
 lativeTo(null);%0A
+
         frame.se
@@ -3011,1156 +3011,4 @@
 %7D%0A%7D%0A
-%0Aclass SortingColumnColorTable extends JTable %7B%0A    private static final Color EVEN_COLOR = new Color(250, 230, 230);%0A    public SortingColumnColorTable(TableModel model) %7B%0A        super(model);%0A    %7D%0A    @Override public Component prepareRenderer(TableCellRenderer tcr, int row, int column) %7B%0A        Component c = super.prepareRenderer(tcr, row, column);%0A        if (isRowSelected(row)) %7B%0A            c.setForeground(getSelectionForeground());%0A            c.setBackground(getSelectionBackground());%0A        %7D else %7B%0A            c.setForeground(getForeground());%0A            c.setBackground(isSortingColumn(column) ? EVEN_COLOR : getBackground());%0A        %7D%0A        return c;%0A    %7D%0A    private boolean isSortingColumn(int column) %7B%0A        RowSorter%3C? extends TableModel%3E sorter = getRowSorter();%0A        if (Objects.nonNull(sorter)) %7B%0A            List%3C? extends RowSorter.SortKey%3E keys = sorter.getSortKeys();%0A            if (keys.isEmpty()) %7B%0A                return false;%0A            %7D%0A            if (column == convertColumnIndexToView(keys.get(0).getColumn())) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A

package private class out, anonymous inner class in