Coloring JTable cells
Hi, this is another JTable question. This forum was so helpful with my last problem, I thought I would return!
I have a table whose cells are filled with strings at the moment. I want to color the cell depending on what string is in the cell, but i want to maintain the ability that columns get highlighted when selected.
I did this by replacing each cell with a JLabel that contained a .jpg of the particular colored string. but then my columsn would not highlight.
Just to clarify: I have strings such as: "A" "T" "C" and "G" and a few others and I want the background of the cell to be a particular color....but maybe changing the color of the font will be sufficient.
Please and Thank you!!
Start reading the API documentation for the TableCellRenderer interface and its implementation the DefaultTableCellRenderer class. It is a 'rubber stamp' that delivers the component to be shown in the visual representation of a table. The default implementation delivers a JLabel. If you override that class you can give that label an appropriate background colour. Start reading and don't fiddle with those JLabels yourself, it has been done for you.
aah thank you!! this is wonderful =D.