Java JTable Alternate Row Color Background in Swings Netbeans

Last modified date

Add the following code to your JTable as shown in the code, at the place Color.yellow add your custom color. Cheers enjoy

output of the code

Alternative Row Color in Java Swings Netbeans

JTable table = new javax.swing.JTable(){
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
        Component c = super.prepareRenderer(renderer, row, column);

        //  Alternate row color

        if (!isRowSelected(row))
        c.setBackground(row % 2 == 0 ? getBackground() : Color.yellow);

        return c;