0

为什么这段代码不能正确运行?并且此 JTable 中的所有项目都有红色?我只调用了一次MonCellRenderer类,但是它循环了很多次。我应该怎么办?

我有调用 jtable 的课程:

public void Tampil(){
 DataTabel.setNumRows(0);
            try {
                String thn ;
                String bln ;
                String btc ;
                DataTabel.setNumRows(0);
                QueryManajemen q = new QueryManajemen();
                String[] kolom = new String[DataTabel.getColumnCount()];
                for (int a = 0; a < DataTabel.getColumnCount(); a++) {
                    kolom[a] = DataTabel.getColumnName(a);
                }
                String[][] data = //some code;

                String[][] notClean = //some code;

                for (int j = 0; j < notClean.length; j++) {
                    listSearch.add(notClean[j][0].toString());
                }

                **tblBatch.setDefaultRenderer(Object.class, new MonCellRenderer());**
            } catch (SQLException ex) {
            }
        }
}

然后调用一个类:

private List<String> listSearch = new ArrayList<String>();

    public List<String> getListSearch() {
        return listSearch;
    }

    public class MonCellRenderer extends DefaultTableCellRenderer {

        public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value,isSelected, hasFocus, row, column);
                if (column == 0 || listSearch.contains(value)) {
                    setBackground(Color.RED);
                } else {
                    setBackground(Color.WHITE);
                }
            return this;
        }
    }
4

0 回答 0