jeudi 31 décembre 2020

Conditional formatting in JTable if statement not executing

I have the following code below. I can make the first if statement work where they are coloured in red.

I cant make the second if statement work whereby it finds a row with the name "RATS-3" then that row would be coloured in black. Can someone advse?

The third else if statement is executed and colours all the remaining cells green

{
        JTable table = new JTable(array, columnHeaders)
      {
    @Override
            public Component prepareRenderer(TableCellRenderer renderer, int rowIndex,int columnIndex) 
            {
                JComponent component = (JComponent) super.prepareRenderer(renderer, rowIndex, columnIndex);  
    
                if(
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_FFES-2")||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_FFES-3")  || 
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_FFES-4")  ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_FOYE-2")  ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_DINO-2") ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_DINO-3") ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_DINO-4") ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_DINO-6")  ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_FOYE-1") ||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_CRUA-1") || 
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_CRUA-2")|| 
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_CRUA-3")||
                        getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_CRUA-4") 
                        
                        && columnIndex == 0) {
                    component.setBackground(Color.RED);
                    
                   if(getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_RATS-3") && columnIndex == 0){
                    component.setBackground(Color.black);  
                    
                    
                }}
                
                 else if(!getValueAt(rowIndex, 1).toString().equalsIgnoreCase("T_RATS-4") && columnIndex == 0){
                    component.setBackground(Color.GREEN);
                }
                
                
    
                return component;
            }

Aucun commentaire:

Enregistrer un commentaire