Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java swing jtable different color each row

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class MyTable extends JTable {
    public MyTable(TableModel model) {
        super(model);
    }

    @Override
    public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
        Component c = super.prepareRenderer(renderer, row, column);
        if (!c.getBackground().equals(getSelectionBackground())) {
            Color colour = (row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY);
            c.setBackground(colour);
        }
        return c;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java swing stripes 
Java :: node-red-docker 
Java :: java remove from arraylist while iterating 
Java :: spring xml 
Java :: nums.add to add the number to the array in java sample 
Java :: get id of html tag by class 
Java :: java all alphabet characters 
Java :: jdbc maven dependency 
Java :: checkindex java 
Java :: how to generate output in various colors in java 
Java :: print hashtable in java 
Java :: what is super in java 
Java :: check if table exist sqlite java 
Java :: select class in selenium 
Java :: java string contains number 
Java :: how to play an audio file in java 
Java :: append button java 
Java :: load a file from classpath spring boot 
Java :: java read each lines in file 
Java :: how to remove components from a JFRame java 
Java :: java check data type 
Java :: spring boot jpa in clause 
Java :: round off java 2 decimal places 
Java :: android studio textview set text int 
Java :: resource leak java 
Java :: float random class java 
Java :: size of queue in java 
Java :: link to method javadoc 
Java :: space in java 
Java :: java calculate time difference 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =