Erro ao trocar cores de uma tabela java

Pessoal pode me ajudar em como resolver esse problema, criei um código para mudar as cores de uma tabela e funciounou tudo ok conseguia roda no netbeans tranquilo no alt + F6 mais quando finalizei e fui compilar apareceu esse erro e num consigo mais nem roda no alt + F6 que o erro aparece o que pode ser?

ant -f C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos -Dnb.internal.action.name=test -Dnb.wait.for.caches=true -Dignore.failing.tests=true test
init:
Deleting: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\built-jar.properties
Compiling 82 source files to C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\classes
C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\src\util\SetColorTable.java:11: error: package sun.swing.table does not exist
import sun.swing.table.DefaultTableCellHeaderRenderer;
C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\src\util\SetColorTable.java:17: error: cannot find symbol
public class SetColorTable extends DefaultTableCellHeaderRenderer{
symbol: class DefaultTableCellHeaderRenderer
C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\src\util\SetColorTable.java:31: error: method does not override or implement a method from a supertype
@Override
C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\src\util\SetColorTable.java:33: error: cannot find symbol
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
symbol: variable super
location: class SetColorTable
C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\src\view\ViewUser.java:119: error: incompatible types: SetColorTable cannot be converted to TableCellRenderer
jTblUser.setDefaultRenderer(Object.class, new SetColorTable(Color.GRAY, Color.LIGHT_GRAY, Color.WHITE, Color.BLACK));
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
5 errors

Posta o fonte da sua classe.

1 curtida
package util;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import sun.swing.table.DefaultTableCellHeaderRenderer;

/**
 *
 * @author joaop
 */
public class SetColorTable extends DefaultTableCellHeaderRenderer{
 
    Color backGroudRow1 = Color.WHITE;
    Color backGroudRow2 = Color.WHITE;
    Color foreGroudRow1 = Color.BLACK;
    Color foreGroudRow2 = Color.BLACK;
    
    public SetColorTable(Color backgroud1, Color backgroud2, Color foregroud1, Color foregroud2) {
        backGroudRow1 = backgroud1;
        backGroudRow2 = backgroud2;
        foreGroudRow1 = foregroud1;
        foreGroudRow2 = foregroud2;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
        
        int tblRowCont =  table.getRowCount();
        Object modelo = table.getValueAt(row, 0);// Pega o objeto que esta na coluna 0   
        for (int i = 0; i < tblRowCont; i++) {
            //System.out.println(i);
            if ((int)modelo%2==0){ //Pega o objeto de modelo e converte em int para estrair o resto para saber se impar ou par
                //Par
                label.setBackground(backGroudRow1); 
            }else{
                //Imprar
                label.setBackground(backGroudRow2);  
            }
        }
       return label;
    }
}

Você não deveria importar o pacote sun.swing.table.DefaultTableCellHeaderRenderer
Troque pelo javax.swing.table.DefaultTableCellRenderer

Troquei tentei recompilar deu essa mensagem!

ant -f C:\\Users\\joaop\\OneDrive\\Documentos\\NetBeansProjects\\JpdsServicos -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\built-clean.properties
Deleting directory C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build
clean:
init:
deps-jar:
Created dir: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build
Updating property file: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\built-jar.properties
Created dir: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\classes
Created dir: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\empty
Created dir: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\generated-sources\ap-source-output
Compiling 82 source files to C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\classes
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 132 files to C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build\classes
compile:
Created dir: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\dist
Copying 1 file to C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\build
Copy libraries to C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\dist\lib.
Building jar: C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\dist\JpdsServicos.jar
To run this application from the command line without Ant, try:
C:\Program Files\Java\zulu8.60.0.21-ca-fx-jdk8.0.322-win_x64/bin/java -jar "C:\Users\joaop\OneDrive\Documentos\NetBeansProjects\JpdsServicos\dist\JpdsServicos.jar"

Tem esse código que apareceu uma importação não utilizada

package util;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author joaop
 */
public class SetTableCabecalho extends JLabel implements TableCellRenderer{
    
    public SetTableCabecalho(Font font, boolean opaque, Color backgroud, Color foregroud/*, Border border*/){
      
        setFont(font);
        setOpaque(opaque);
        setBackground(backgroud);
        setForeground(foregroud);
         //setBorder(border); //pega a borda que o nebeans criar procura pela nome variavel da tabela
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        setText(value.toString());
        return this;
    }
    
}

essa aqui ta falando que não é ultilizada

import javax.swing.border.Border;

Não tem nenhum erro nas mensagens
:man_shrugging:

1 curtida

Muito obrigado a compilação deu certo